<div dir="ltr">The conversion to micro seconds has not been optimized as much for os:perf_counter/1 as it has for the other functions which is why there is such a large difference. If I use os:perf_counter() instead I get about 1.3-1.4. The remaining 30%-40% comes from the fact that bignums are returned by os:perf_counter() and not smalls.<div><br></div><div>I did a quick hack to see what the result would be if os:perf_counter/1 used the same optimization as monotonic/system_time and then the time is about the same for all four time measurement variants. On modern hw running modern OS's the gain of os:perf_counter over erlang:system_time will not be all that great. <br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 10, 2016 at 3:29 AM, Michael Truog <span dir="ltr"><<a href="mailto:mjtruog@gmail.com" target="_blank">mjtruog@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi,<br>
<br>
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 (<a href="http://erlang.org/doc/man/os.html#perf_counter-1" rel="noreferrer" target="_blank">http://erlang.org/doc/man/os.<wbr>html#perf_counter-1</a>). 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)?<br>
<br>
The results from <a href="https://github.com/okeuday/erlbench" rel="noreferrer" target="_blank">https://github.com/okeuday/erl<wbr>bench</a> when I do "make" is:<br>
N == 10000 (10 runs)<br>
18_bxor_abs get: 2507.1 us ( 1.2)<br>
18_erlang:system_tim get: 2095.7 us ( 1.0)<br>
18_monotonic get: 2186.1 us ( 1.0)<br>
18_rand_exs1024 get: 13539.0 us ( 6.5)<br>
18_rand_exs64 get: 11205.1 us ( 5.3)<br>
18_rand_exsplus get: 6171.4 us ( 2.9)<br>
19_os:perf_counter/1 get: 5214.4 us ( 2.5)<br>
crypto:rand_uniform/ get: 88909.9 us ( 42.4)<br>
os:timestamp/0 get: 2214.8 us ( 1.1)<br>
random:uniform/1 get: 6058.7 us ( 2.9)<br>
random_wh06_int:unif get: 14252.9 us ( 6.8)<br>
random_wh82:uniform/ get: 6049.0 us ( 2.9)<br>
random_wh82_int:unif get: 6595.8 us ( 3.1)<br>
<br>
The machine is:<br>
Core i7 2670QM 2.2GHz 1 cpu, 4 cores/cpu, 2 hts/core<br>
L2:4×256KB L3:6MB RAM:8GB:DDR3-1333MHz<br>
Sandy Bridge-HE-4 (Socket G2)<br>
<br>
Thanks,<br>
Michael<br>
<br>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
</blockquote></div><br></div></div></div>