summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_recfunctions.py
diff options
context:
space:
mode:
authorAntoine Pitrou <antoine@python.org>2014-12-03 11:43:28 +0100
committerAntoine Pitrou <antoine@python.org>2015-04-04 18:45:14 +0200
commitcca2c1a4fecfa5533b5579204c5f28a12c5b078a (patch)
treecdad45dbf12ce88fbfdef9dbae343c425c56d01e /numpy/lib/tests/test_recfunctions.py
parentc3cd4bfa57992bb804f5efc41e93e5354d7dfef3 (diff)
downloadnumpy-cca2c1a4fecfa5533b5579204c5f28a12c5b078a.tar.gz
ENH: cache dtype.__hash__
Computing the type of a dhash can be slow for complex (e.g. structured) dtypes. Hashing dtypes can be useful in some applications, such as when doing type-based dispatching, and speed can be critical in those cases. This enhancement caches the once-computed hash value in the dtype structure, so as to save time on further lookups. The cached value is invalidated in the rare cases where the dtype is mutated. Benchmarks numbers: python3.4 -m timeit -s "import numpy as np; t=np.dtype('uint64')" "hash(t)" * before patch: 1000000 loops, best of 3: 0.498 usec per loop * after patch: 10000000 loops, best of 3: 0.0616 usec per loop python3.4 -m timeit -s "import numpy as np; t=np.dtype([(s, 'f') for s in 'abcdefghij'])" "hash(t)" * before patch: 100000 loops, best of 3: 4.43 usec per loop * after patch: 10000000 loops, best of 3: 0.0603 usec per loop Closes #5339.
Diffstat (limited to 'numpy/lib/tests/test_recfunctions.py')
0 files changed, 0 insertions, 0 deletions