Skip to content

Instantly share code, notes, and snippets.

@juhasch
Created August 28, 2023 18:15
Show Gist options
  • Save juhasch/cc4d3d6365f011e0d863e92fbc5633bf to your computer and use it in GitHub Desktop.
Save juhasch/cc4d3d6365f011e0d863e92fbc5633bf to your computer and use it in GitHub Desktop.
Zarr benchmark
"""
Benchmark for reading and writing zarr datasets
"""
import zarr
import numpy as np
from tqdm import tqdm
from time import time
num = 1000
filename = 'zarr_test'
# Write dataset
za = zarr.open(filename, 'w')
t0 = time()
for idx in tqdm(range(num)):
data = np.expand_dims(np.random.random((512, 512)), axis=0)
if idx == 0:
za.array(name='blob', data=data)
else:
za.blob.append(data)
t1 = time()
print(f'Write duration: {(t1-t0):.2f} s')
print(f'Write throughput: {num/(t1-t0):.2f} frames/s')
# Read dataset
za = zarr.open(filename, 'r')
t0 = time()
for idx in tqdm(range(num)):
data = za.blob[idx]
t1 = time()
print(f'Read duration: {(t1-t0):.2f} s')
print(f'Read throughput: {num/(t1-t0):.2f} frames/s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment