Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reproducible example to LRUStoreCache docstring #465

Open
notmatthancock opened this issue Aug 9, 2019 · 0 comments
Open

Add reproducible example to LRUStoreCache docstring #465

notmatthancock opened this issue Aug 9, 2019 · 0 comments

Comments

@notmatthancock
Copy link

The example given for LRUStoreCache is helpful, but unfortunately not run-able since it depends on a remote connection. I came up with the following example that uses a dummy "slow dict" store to be used instead as an example.

However, the factor of 5 on max_size was done through guess-work and should be set to something more appropriate for illustration.

class SlowDictStore(zarr.DictStore):
    def __getitem__(self, item):
        if not item.endswith('.zarray'):
            import time
            time.sleep(1)
        return super().__getitem__(item)

x = np.zeros(128)

store = SlowDictStore()
cache = zarr.LRUStoreCache(store=store, max_size=x.nbytes*5)
root = zarr.group(store=cache)

root.create_dataset('x', data=x.copy(), compressor=None)
root.create_dataset('y', data=x.copy(), compressor=None)

cache.invalidate()

from timeit import timeit
print('1st access x:', timeit('root["x"][:]', number=1, globals=globals()))
print('2nd access x:', timeit('root["x"][:]', number=1, globals=globals()))

print('1st access y:', timeit('root["y"][:]', number=1, globals=globals()))
print('2nd access y:', timeit('root["y"][:]', number=1, globals=globals()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant