1
>>> import numpy as np
>>> a1 = np.arange(10000, dtype=np.int32)
>>> a2 = np.arange(10000, dtype=np.float32)
>>> %timeit -n 1000 -r 5 np.sum(a1)
110 µs ± 1.18 µs per loop (mean ± std. dev. of 5 runs, 1000 loops each)
>>> %timeit -n 1000 -r 5 np.sum(a2)
50.1 µs ± 895 ns per loop (mean ± std. dev. of 5 runs, 1000 loops each)

Can anybody please explain to me this massive difference between speed for the same operation but with different dtypes?

This has really confused me. Naively I would think the ops on int32 would be faster but it was a shock to see the above results. Thanks for the help in advance.

Xi Ching
  • 11
  • 1

0 Answers0