Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / benchmark / histogram_filling_numpy.py
1 from __future__ import print_function
2 import numpy as np
3 # pip install fast-histogram
4 from fast_histogram import histogram1d
5 import timeit
6
7 x = np.random.rand(1 << 20)
8 nrepeat = 10
9
10 print(timeit.timeit("np.histogram(x, bins=100, range=(0, 1))",
11                     "from __main__ import x, np", number=nrepeat) / (nrepeat * len(x)) / 1e-9)
12                     
13 print(timeit.timeit("histogram1d(x, bins=100, range=(0, 1))",
14                     "from __main__ import x, histogram1d", number=nrepeat) / (nrepeat * len(x)) / 1e-9)