Rb Tree, Benchmarking rate per CPU second

Is there a way to benchmark a block of Julia code in rate per CPU second?
Example in Perl, see “timethese” How to benchmark Perl code for speed

It outputs something like
10 wallclock secs (10.32 usr + 0.00 sys = 10.32 CPU) @ 150112.98/s (n=1549166)

Where i am interested in the “150112.98/s” which is the rate per CPU second.

Another question, is there any Red and Black Tree library other than the default one from DataStructures? From what i could check It misses very basic functions.

I don’t know the answer to your first question. As for your second question, please open an issue on the DataStructures issues page (https://github.com/JuliaCollections/DataStructures.jl/issues) for the missing features of red-black trees that you need. Also, note that the sorted containers in DataStructures.jl have more features than the current implementation of red-black trees. The sorted containers are based on 2-3 trees, another kind of balanced-tree data structure.

If I’m understanding that link correctly, I think you could get the result you’re interested in by just taking the reciprocal of the mean time from BenchmarkTools @benchmark:

julia> f(x) = sqrt(x) + 1
f (generic function with 1 method)

julia> using BenchmarkTools

julia> benchmark_result = @benchmark f(x) setup=(x = rand())
BechmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  1.448 ns … 19.763 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     1.461 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.473 ns ±  0.319 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▁█▅▄▃▁                                                      
  ██████▅▃▂▃▂▂▂▁▂▂▁▁▂▂▁▁▂▂▁▁▁▂▂▂▂▂▁▂▁▁▁▂▂▂▂▂▂▂▁▁▂▁▂▂▂▂▂▁▁▁▁▂ ▃
  1.45 ns        Histogram: frequency by time        1.69 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.
# time(mean(benchmark_result)) gives the mean time per execution in ns
julia> 1 / (time(mean(benchmark_result)) * 1e-9)
6.79023168134692e8

(Although the mean may not actually be as informative, since it can be heavily influenced by, for example, your CPU switching off to work on something else in the middle of a run. The minimum or median time may be more useful in comparing functions.)