FHist.jl icon indicating copy to clipboard operation
FHist.jl copied to clipboard

add static compilation example

Open Moelf opened this issue 4 months ago • 2 comments
trafficstars

The timing is distribution dependent

julia> @benchmark Hist1D(x; binedges=range(-1,1;length=11)) setup=x=rand(10^6)
BenchmarkTools.Trial: 1621 samples with 1 evaluation.
 Range (min … max):  1.418 ms …   2.619 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     1.803 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.814 ms ± 136.134 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

                    ▂▃▂▂▆▇▄▆▆███▆▄▇▆▆▃▆▃▃▄▂▃▁▂▁
  ▂▂▂▂▃▁▁▂▃▂▄▄▄▄▄▆▇████████████████████████████▆▇▆▆▅▅▅▅▆▅▄▄▂▂ ▆
  1.42 ms         Histogram: frequency by time        2.14 ms <

 Memory estimate: 592 bytes, allocs estimate: 8.

julia> @benchmark Hist1D(x; binedges=range(-1,1;length=11)) setup=x=randn(10^6)
BenchmarkTools.Trial: 710 samples with 1 evaluation.
 Range (min … max):  5.025 ms …  5.351 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     5.133 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   5.136 ms ± 46.322 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

                 ▃ ▃▂▃ ▄▁▃▂█▅▃▅▆▄▂▃  ▅▁
  ▃▁▂▃▃▃▁▅▅▄▆▅▆▅▇█▇████████████████▇▇██▆▆▅▅▆▇▄▄▆▅▃▃▃▂▃▄▄▃▃▃▂ ▅
  5.03 ms        Histogram: frequency by time        5.26 ms <

 Memory estimate: 592 bytes, allocs estimate: 8.
In [1]: import numpy as np

In [2]: x = np.random.random(10**6)

In [3]: %timeit np.histogram(x, bins=10, range=(-1, 1))
6.13 ms ± 66.7 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [4]: x = np.random.normal(size=10**6)

In [5]: %timeit np.histogram(x, bins=10, range=(-1, 1))
8.09 ms ± 30.9 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Moelf avatar Jul 04 '25 21:07 Moelf