77import sys
88import tempfile
99import time
10- from typing import Optional , NamedTuple
10+ from typing import NamedTuple , Optional
1111
1212import h5py
1313import numpy
1414
15-
1615# Set affinity and env. var. before importing hdf5plugin
1716
1817if len (sys .argv ) >= 2 :
2827# Directory where to run read/write benchmarks
2928DIRECTORY = "/dev/shm"
3029
30+
3131# Function to get data to use for tests
3232def get_data ():
3333 with h5py .File ("/dev/shm/kevlar.h5" ) as h5file :
3434 return h5file ["/entry/data/data" ][::10 ] # Take 100 frames
3535
3636
37- import hdf5plugin
37+ import hdf5plugin # noqa: E402
3838
3939
4040class Result (NamedTuple ):
@@ -46,21 +46,18 @@ class Result(NamedTuple):
4646 read_duration : float
4747 chunks : tuple [int ]
4848
49- compression_rate = property (
50- lambda self : self .raw_nbytes / self .compressed_nbytes )
49+ compression_rate = property (lambda self : self .raw_nbytes / self .compressed_nbytes )
5150 write_speed = property (
5251 lambda self : (self .raw_nbytes / 1024 ** 2 ) / self .write_duration ,
53- doc = "Unit: MB/sec" )
52+ doc = "Unit: MB/sec" ,
53+ )
5454 read_speed = property (
5555 lambda self : (self .raw_nbytes / 1024 ** 2 ) / self .read_duration ,
56- doc = "Unit: MB/sec" )
57-
58-
59- def benchmark (
60- data : numpy .ndarray ,
61- directory : Optional [str ] = None ,
62- ** kwargs
63- ) -> Result :
56+ doc = "Unit: MB/sec" ,
57+ )
58+
59+
60+ def benchmark (data : numpy .ndarray , directory : Optional [str ] = None , ** kwargs ) -> Result :
6461 """Run benchmark for given conditions
6562
6663 :param data: Dataset to use
@@ -73,15 +70,16 @@ def benchmark(
7370 else :
7471 dirname = directory
7572
76- filename = os .path .join (dirname , ' hdf5plugin_benchmark.h5' )
73+ filename = os .path .join (dirname , " hdf5plugin_benchmark.h5" )
7774
7875 if os .path .exists (filename ):
7976 os .remove (filename )
8077
8178 # Compression
8279 with h5py .File (filename , "w" ) as h5file :
8380 dataset = h5file .create_dataset (
84- "data" , shape = data .shape , dtype = data .dtype , ** kwargs )
81+ "data" , shape = data .shape , dtype = data .dtype , ** kwargs
82+ )
8583 start_write_time = time .perf_counter ()
8684 dataset [:] = data
8785 dataset .flush ()
@@ -91,16 +89,18 @@ def benchmark(
9189 with h5py .File (filename , "r" ) as h5file :
9290 dataset = h5file ["data" ]
9391 start_time = time .perf_counter ()
94- read_data = dataset [()]
92+ dataset [()]
9593 read_duration = time .perf_counter () - start_time
9694 storage_size = dataset .id .get_storage_size ()
9795 chunks = dataset .chunks
98-
96+
9997 os .remove (filename )
10098
101- return Result (data .nbytes , storage_size , write_duration , read_duration , chunks = chunks )
99+ return Result (
100+ data .nbytes , storage_size , write_duration , read_duration , chunks = chunks
101+ )
102+
102103
103-
104104DEFAULT_FILTERS = { # Filters available with h5py/libhdf5
105105 "Raw" : None ,
106106 "GZip" : "gzip" ,
@@ -114,28 +114,34 @@ def benchmark(
114114}
115115
116116BITSHUFFLE_FILTERS = {
117- "Bitshuffle-lz4" : hdf5plugin .Bitshuffle (cname = ' lz4' ),
118- "Bitshuffle-zstd" : hdf5plugin .Bitshuffle (cname = ' zstd' ),
117+ "Bitshuffle-lz4" : hdf5plugin .Bitshuffle (cname = " lz4" ),
118+ "Bitshuffle-zstd" : hdf5plugin .Bitshuffle (cname = " zstd" ),
119119}
120-
120+
121121BLOSC_FILTERS = {}
122- for cname in ('lz4' , 'blosclz' , 'lz4' , 'lz4hc' , 'snappy' , 'zlib' , 'zstd' ):
123- for shuffle_name , shuffle in [('NoShuffle' , hdf5plugin .Blosc .NOSHUFFLE ),
124- ('Shuffle' , hdf5plugin .Blosc .SHUFFLE ),
125- ('BitShuffle' , hdf5plugin .Blosc .BITSHUFFLE )]:
126- for clevel in [5 ]: #(1, 3, 5, 9):
122+ for cname in ("lz4" , "blosclz" , "lz4" , "lz4hc" , "snappy" , "zlib" , "zstd" ):
123+ for shuffle_name , shuffle in [
124+ ("NoShuffle" , hdf5plugin .Blosc .NOSHUFFLE ),
125+ ("Shuffle" , hdf5plugin .Blosc .SHUFFLE ),
126+ ("BitShuffle" , hdf5plugin .Blosc .BITSHUFFLE ),
127+ ]:
128+ for clevel in [5 ]: # (1, 3, 5, 9):
127129 BLOSC_FILTERS [f"Blosc-{ cname } -{ shuffle_name } -{ clevel } " ] = hdf5plugin .Blosc (
128- cname = cname , clevel = clevel , shuffle = shuffle )
130+ cname = cname , clevel = clevel , shuffle = shuffle
131+ )
129132
130133
131134BLOSC2_FILTERS = {}
132- for cname in ('lz4' , 'blosclz' , 'lz4' , 'lz4hc' , 'zlib' , 'zstd' ):
133- for filters_name , filters in [('NoFilter' , hdf5plugin .Blosc2 .NOFILTER ),
134- ('Shuffle' , hdf5plugin .Blosc2 .SHUFFLE ),
135- ('BitShuffle' , hdf5plugin .Blosc2 .BITSHUFFLE )]:
136- for clevel in [5 ]: # (1, 3, 5, 9):
137- BLOSC2_FILTERS [f"Blosc2-{ cname } -{ filters_name } -{ clevel } " ] = hdf5plugin .Blosc2 (
138- cname = cname , clevel = clevel , filters = filters )
135+ for cname in ("lz4" , "blosclz" , "lz4" , "lz4hc" , "zlib" , "zstd" ):
136+ for filters_name , filters in [
137+ ("NoFilter" , hdf5plugin .Blosc2 .NOFILTER ),
138+ ("Shuffle" , hdf5plugin .Blosc2 .SHUFFLE ),
139+ ("BitShuffle" , hdf5plugin .Blosc2 .BITSHUFFLE ),
140+ ]:
141+ for clevel in [5 ]: # (1, 3, 5, 9):
142+ BLOSC2_FILTERS [f"Blosc2-{ cname } -{ filters_name } -{ clevel } " ] = (
143+ hdf5plugin .Blosc2 (cname = cname , clevel = clevel , filters = filters )
144+ )
139145
140146
141147FILTERS = {
0 commit comments