正如在说明书上说,http://www.erlang.org/erldoc?q=erlang:nowerlang:now/0比os:timestamp/0更快?
如果您不需要返回值是唯一的,单调递增的,使用的操作系统:时间戳/ 0来避免一些开销。
OS:时间戳/ 0应该比二郎神更快:现在/ 0
但我在我的电脑上测试与定时器:TC/3,为千万通话,在微秒所花费的时间是:
二郎:现在951000
OS:时间戳1365000
为什么二郎:现在比OS/0更快:时间戳/ 0?
我的操作系统:Windows 7 x64,erlang版本:R16B01。
------------------编辑-----------------
我又写测试代码parallel(100个线程),os:timestamp/0并行执行得更好。这里是数据:
----- single thread ------
erlang:now 95000
os:timestamp 147000
----- multi thread ------
erlang:now 333000
os:timestamp 91000
所以,我认为“开销”是平行的。