1. timer模块中有函数tc(), 用于度量函数执行所消耗的时间, tc/1, tc/2的相关源码如下:
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}.
now_diff({A2, B2, C2}, {A1, B1, C1}) ->
((A2-A1)*1000000 + B2-B1)*1000000 + C2-C1.
时间: 2024-11-10 19:22:45