[erlang-questions] os:perf_counter/1 is slow

Michael Truog mjtruog@REDACTED
Wed Aug 10 03:29:13 CEST 2016


Hi,

When I test the speed of os:perf_counter/1 as a potential source of 
pseudo-randomness from the microseconds result, the speed is slower than 
os:timestamp/0, erlang:monotonic_time/0 and erlang:system_time/1 which I 
found surprising, since the documentation claims os:perf_counter/1 
should be fast (http://erlang.org/doc/man/os.html#perf_counter-1).  
Should this be explained as a hardware problem due to lower-level 
instruction usage that is hardware dependent, or is this still being 
improved (it is new in 19.0)?

The results from https://github.com/okeuday/erlbench when I do "make" is:
N == 10000 (10 runs)
          18_bxor_abs get:     2507.1 us (  1.2)
18_erlang:system_tim get:     2095.7 us (  1.0)
         18_monotonic get:     2186.1 us (  1.0)
      18_rand_exs1024 get:    13539.0 us (  6.5)
        18_rand_exs64 get:    11205.1 us (  5.3)
      18_rand_exsplus get:     6171.4 us (  2.9)
19_os:perf_counter/1 get:     5214.4 us (  2.5)
crypto:rand_uniform/ get:    88909.9 us ( 42.4)
       os:timestamp/0 get:     2214.8 us (  1.1)
     random:uniform/1 get:     6058.7 us (  2.9)
random_wh06_int:unif get:    14252.9 us (  6.8)
random_wh82:uniform/ get:     6049.0 us (  2.9)
random_wh82_int:unif get:     6595.8 us (  3.1)

The machine is:
Core i7 2670QM 2.2GHz 1 cpu, 4 cores/cpu, 2 hts/core
L2:4×256KB L3:6MB RAM:8GB:DDR3-1333MHz
Sandy Bridge-HE-4 (Socket G2)

Thanks,
Michael




More information about the erlang-questions mailing list