erlang:phash2(now())

Lev Walkin vlm at lionet.info
Sat Oct 2 10:00:40 EDT 2010


In riak sources there are many references to  
erlang:phash2(erlang:now()).

Why not use idiomatic make_ref() or at the very least  
erlang:phash2(make_ref()), which is faster?

1> perftest:comprehensive(100000, fun() -> erlang:phash2(erlang:now())  
end).
Sequential 100000 cycles in ~1 seconds (193510 cycles/s)
Parallel 2 100000 cycles in ~1 seconds (187282 cycles/s)
Parallel 4 100000 cycles in ~1 seconds (197310 cycles/s)
Parallel 10 100000 cycles in ~1 seconds (182890 cycles/s)
Parallel 100 100000 cycles in ~0 seconds (208671 cycles/s)
[197310,182890,208671]
2> perftest:comprehensive(100000, fun() -> erlang:phash2(make_ref())  
end).
Sequential 100000 cycles in ~0 seconds (323952 cycles/s)
Parallel 2 100000 cycles in ~0 seconds (301875 cycles/s)
Parallel 4 100000 cycles in ~0 seconds (308568 cycles/s)
Parallel 10 100000 cycles in ~0 seconds (287875 cycles/s)
Parallel 100 100000 cycles in ~0 seconds (326416 cycles/s)
[308568,287875,326416]
3> perftest:comprehensive(100000, fun() -> make_ref() end).
Sequential 100000 cycles in ~0 seconds (1299765 cycles/s)
Parallel 2 100000 cycles in ~0 seconds (934492 cycles/s)
Parallel 4 100000 cycles in ~0 seconds (1111679 cycles/s)
Parallel 10 100000 cycles in ~0 seconds (1241434 cycles/s)
Parallel 100 100000 cycles in ~0 seconds (1264350 cycles/s)
[1111679,1241434,1264350]
4>

make_ref is 6 times faster than erlang:phash2(make_ref()) which is 50%  
faster than erlang:phash2(now()).

Of course, in the grand scheme of things this might not be your  
biggest bottleneck, but why hashing now() when there exsists an  
idiomatic make_ref() solution? Am I missing something?

-- 
Lev Walkin
vlm at lionet.info




More information about the riak-users mailing list