纪秀峰]:erlang:now() os:timestamp() 比较

来源:互联网 发布:js post get请求 编辑:程序博客网 时间:2024/05/04 18:50
纪秀峰]:erlang:now() os:timestamp() 比较
受影响的文件:    benchmark/src/now_timestamp.erl
  • master
commit ceefc934e92fc3ffd66683012d0e306be175302d 1 parent16cbbe7
jixiufjixiuf authored January 25, 2013
Show diff stats Hide diff stats
Showing 1 changed file with32 additions and 0 deletions.
  1. +320 benchmark/src/now_timestamp.erl
32  benchmark/src/now_timestamp.erl
View
  @@ -0,0 +1,32 @@  +%%%-------------------------------------------------------------------  +%%% @author 纪秀峰 <jixiuf@gmail.com>  +%%% @doc  +%%%  +%%% @end  +%%% Created : 2013-01-25 10:21 by 纪秀峰 <jixiuf@gmail.com>  +%%%-------------------------------------------------------------------  +-module(now_timestamp).  +-export([test/1]).  +  +%% 测erlang:now() 与os:timestamp() 哪个速度更快  +%% (emacs@jf.org)22> now_timestamp:test(10000).  +%% erlang:now():{940,ok}  +%% os:timestamp():{522,ok}  +%% 测试结果显示 os:timestamp() 较快  +  +test(N)->  + T=timer:tc(fun () -> now_benchmark(N) end),  + io:format("erlang:now():~p~n",[T]) ,  + T2=timer:tc(fun () -> os_timestamp_benchmark(N) end),  + io:format("os:timestamp():~p~n",[T2])  + .  +now_benchmark(0)->ok;  +now_benchmark(N)->  + now(),  + now_benchmark(N-1)  + .  +os_timestamp_benchmark(0)->ok;  +os_timestamp_benchmark(N)->  + os:timestamp(),  + os_timestamp_benchmark(N-1)  + .
0 0
原创粉丝点击