@@ -250,21 +250,23 @@ def store_arrays_in_zarr(arrays, output_dir):
250
250
return total_time
251
251
252
252
253
- def measure_memory_usage (func , * args , ** kwargs ):
254
- """Measure memory usage of a function."""
255
- print ("\n Measuring memory usage ..." )
253
+ def measure_memory_and_time (func , * args , ** kwargs ):
254
+ """Measure memory usage and execution time of a function in a single run ."""
255
+ print ("\n Measuring memory and time ..." )
256
256
257
257
def wrapper ():
258
258
return func (* args , ** kwargs )
259
259
260
- # Measure memory usage during execution
261
- mem_usage = memory_usage (wrapper , interval = 0.1 , timeout = None )
260
+ # Measure memory usage and get return value ( execution time)
261
+ mem_usage , exec_time = memory_usage (wrapper , interval = 0.1 , timeout = None , retval = True )
262
262
263
263
max_memory_mb = max (mem_usage )
264
264
min_memory_mb = min (mem_usage )
265
265
memory_increase_mb = max_memory_mb - min_memory_mb
266
266
267
- return max_memory_mb , min_memory_mb , memory_increase_mb , mem_usage
267
+ memory_stats = (max_memory_mb , min_memory_mb , memory_increase_mb , mem_usage )
268
+
269
+ return exec_time , memory_stats
268
270
269
271
270
272
def get_storage_size (path ):
@@ -590,7 +592,8 @@ def create_comparison_plot(sizes_mb, tstore_results, h5py_results, zarr_results)
590
592
591
593
# Adjust layout and add overall title
592
594
plt .tight_layout ()
593
- fig .suptitle (f'Performance Comparison: { N_ARRAYS } arrays, { total_data_mb :.1f} MB total data' ,
595
+ total_data_gb = total_data_mb / 1024
596
+ fig .suptitle (f'Performance Comparison: { N_ARRAYS } arrays, { total_data_gb :.2f} GB total data' ,
594
597
fontsize = 16 , fontweight = 'bold' , y = 0.98 )
595
598
596
599
# Add extra space at the top for the title
@@ -860,8 +863,7 @@ def main():
860
863
print ("\n " + "=" * 60 )
861
864
print ("BENCHMARKING h5py" )
862
865
print ("=" * 60 )
863
- h5py_memory_stats = measure_memory_usage (store_arrays_in_h5py , arrays , OUTPUT_FILE_H5PY )
864
- h5py_time = store_arrays_in_h5py (arrays , OUTPUT_FILE_H5PY )
866
+ h5py_time , h5py_memory_stats = measure_memory_and_time (store_arrays_in_h5py , arrays , OUTPUT_FILE_H5PY )
865
867
h5py_storage_size = get_storage_size (OUTPUT_FILE_H5PY )
866
868
h5py_access_time = measure_access_time (arrays , (h5py_time , h5py_memory_stats , h5py_storage_size ), "h5py" )
867
869
h5py_read_time = measure_complete_read_time (arrays , (h5py_time , h5py_memory_stats , h5py_storage_size ), "h5py" )
@@ -877,8 +879,7 @@ def main():
877
879
print ("\n " + "=" * 60 )
878
880
print ("BENCHMARKING zarr" )
879
881
print ("=" * 60 )
880
- zarr_memory_stats = measure_memory_usage (store_arrays_in_zarr , arrays , OUTPUT_DIR_ZARR )
881
- zarr_time = store_arrays_in_zarr (arrays , OUTPUT_DIR_ZARR )
882
+ zarr_time , zarr_memory_stats = measure_memory_and_time (store_arrays_in_zarr , arrays , OUTPUT_DIR_ZARR )
882
883
zarr_storage_size = get_storage_size (OUTPUT_DIR_ZARR )
883
884
zarr_access_time = measure_access_time (arrays , (zarr_time , zarr_memory_stats , zarr_storage_size ), "zarr" )
884
885
zarr_read_time = measure_complete_read_time (arrays , (zarr_time , zarr_memory_stats , zarr_storage_size ), "zarr" )
@@ -892,8 +893,7 @@ def main():
892
893
print ("\n " + "=" * 60 )
893
894
print ("BENCHMARKING TreeStore" )
894
895
print ("=" * 60 )
895
- tstore_memory_stats = measure_memory_usage (store_arrays_in_treestore , arrays , OUTPUT_DIR_TSTORE )
896
- tstore_time = store_arrays_in_treestore (arrays , OUTPUT_DIR_TSTORE )
896
+ tstore_time , tstore_memory_stats = measure_memory_and_time (store_arrays_in_treestore , arrays , OUTPUT_DIR_TSTORE )
897
897
tstore_storage_size = get_storage_size (OUTPUT_DIR_TSTORE )
898
898
tstore_access_time = measure_access_time (arrays , (tstore_time , tstore_memory_stats , tstore_storage_size ), "TreeStore" )
899
899
tstore_read_time = measure_complete_read_time (arrays , (tstore_time , tstore_memory_stats , tstore_storage_size ), "TreeStore" )
0 commit comments