timer misc

1.  timer模块中有函数tc(), 用于度量函数执行所消耗的时间, tc函数的相关源码如下:

tc(F) ->
    Before = os:timestamp(),
    Val = F(),
    After = os:timestamp(),
    {now_diff(After, Before), Val}.

 tc(F, A) ->
     Before = os:timestamp(),
     Val = apply(F, A),
     After = os:timestamp(),
     {now_diff(After, Before), Val}.

 tc(M, F, A) ->
     Before = os:timestamp(),
     Val = apply(M, F, A),
     After = os:timestamp(),
     {now_diff(After, Before), Val}.

 now_diff({A2, B2, C2}, {A1, B1, C1}) ->
     ((A2-A1)*1000000 + B2-B1)*1000000 + C2-C1.

 

posted @ 2016-03-09 12:00  kamfon  阅读(209)  评论(0编辑  收藏  举报