MCPcopy Create free account
hub / github.com/boostorg/histogram / compare_1d

Function compare_1d

test/speed_numpy.py:14–36  ·  view source on GitHub ↗
(n, distrib)

Source from the content-addressed store, hash-verified

12from histogram.axis import regular
13
14def compare_1d(n, distrib):
15 if distrib == 0:
16 r = np.random.rand(n)
17 else:
18 r = 0.5 + 0.3 * np.random.randn(n)
19
20 best_numpy = float("infinity")
21 best_boost = float("infinity")
22 for k in xrange(20):
23 t = timer()
24 w, xe = np.histogram(r, bins=100, range=(0.0, 1.0))
25 t = timer() - t
26 best_numpy = min(t, best_numpy)
27
28 h = histogram(regular(100, 0, 1))
29 t = timer()
30 h.fill(r)
31 t = timer() - t
32 best_boost = min(t, best_boost)
33 assert(np.all(w == np.array(h)[:-2]))
34
35 print "py:numpy %.3f" % best_numpy
36 print "py:hd_sd %.3f" % best_boost
37
38def compare_2d(n, distrib):
39 if distrib == 0:

Callers 1

speed_numpy.pyFile · 0.70

Calls 3

regularClass · 0.90
histogramMethod · 0.80
histogramClass · 0.50

Tested by

no test coverage detected