|
|
@ -9,7 +9,6 @@ |
|
|
|
, tc/3 |
|
|
|
, ts/4 |
|
|
|
, tm/5 |
|
|
|
, cvrTimeUnit/3 |
|
|
|
, test/1 |
|
|
|
]). |
|
|
|
|
|
|
@ -19,7 +18,7 @@ tc(F) -> |
|
|
|
T1 = erlang:monotonic_time(), |
|
|
|
Val = F(), |
|
|
|
T2 = erlang:monotonic_time(), |
|
|
|
Time = cvrTimeUnit(T2 - T1, native, nanosecond), |
|
|
|
Time = erlang:convert_time_unit(T2 - T1, native, nanosecond), |
|
|
|
{Time, Val}. |
|
|
|
|
|
|
|
%% Measure the execution time (in nanoseconds) for Fun(Args). |
|
|
@ -28,7 +27,7 @@ tc(F, A) -> |
|
|
|
T1 = erlang:monotonic_time(), |
|
|
|
Val = apply(F, A), |
|
|
|
T2 = erlang:monotonic_time(), |
|
|
|
Time = cvrTimeUnit(T2 - T1, native, nanosecond), |
|
|
|
Time = erlang:convert_time_unit(T2 - T1, native, nanosecond), |
|
|
|
{Time, Val}. |
|
|
|
|
|
|
|
%% Measure the execution time (in nanoseconds) for an MFA. |
|
|
@ -37,39 +36,9 @@ tc(M, F, A) -> |
|
|
|
T1 = erlang:monotonic_time(), |
|
|
|
Val = apply(M, F, A), |
|
|
|
T2 = erlang:monotonic_time(), |
|
|
|
Time = cvrTimeUnit(T2 - T1, native, nanosecond), |
|
|
|
Time = erlang:convert_time_unit(T2 - T1, native, nanosecond), |
|
|
|
{Time, Val}. |
|
|
|
|
|
|
|
-spec cvrTimeUnit(Time :: integer(), FromUnit :: erlang:time_unit(), ToUnit :: erlang:time_unit()) -> ConvertedTime :: integer(). |
|
|
|
cvrTimeUnit(Time, FromUnit, ToUnit) -> |
|
|
|
try |
|
|
|
FU = |
|
|
|
case FromUnit of |
|
|
|
native -> erts_internal:time_unit(); |
|
|
|
perf_counter -> erts_internal:perf_counter_unit(); |
|
|
|
nanosecond -> 1000000000; |
|
|
|
microsecond -> 1000000; |
|
|
|
millisecond -> 1000; |
|
|
|
second -> 1 |
|
|
|
end, |
|
|
|
TU = |
|
|
|
case ToUnit of |
|
|
|
native -> erts_internal:time_unit(); |
|
|
|
perf_counter -> erts_internal:perf_counter_unit(); |
|
|
|
nanosecond -> 1000000000; |
|
|
|
microsecond -> 1000000; |
|
|
|
millisecond -> 1000; |
|
|
|
second -> 1 |
|
|
|
end, |
|
|
|
case Time < 0 of |
|
|
|
true -> (TU * Time - (FU - 1)) div FU; |
|
|
|
_ -> TU * Time div FU |
|
|
|
end |
|
|
|
catch |
|
|
|
_ : _ -> |
|
|
|
erlang:error(badarg, [Time, FromUnit, ToUnit]) |
|
|
|
end. |
|
|
|
|
|
|
|
%% 单进程循环测试:LoopTimes是循环次数 |
|
|
|
%% utTc:ts(LoopTimes, Module, Function, ArgsList). |
|
|
|
%% 多进程并发测试:SpawnProcessesCount是并发的进程数 LoopTimes是循环次数 |
|
|
@ -79,7 +48,7 @@ doTc(M, F, A) -> |
|
|
|
T1 = erlang:monotonic_time(), |
|
|
|
apply(M, F, A), |
|
|
|
T2 = erlang:monotonic_time(), |
|
|
|
cvrTimeUnit(T2 - T1, native, nanosecond). |
|
|
|
erlang:convert_time_unit(T2 - T1, native, nanosecond). |
|
|
|
|
|
|
|
distribution(List, Aver) -> |
|
|
|
distribution(List, Aver, 0, 0). |
|
|
@ -203,7 +172,7 @@ test(N) -> |
|
|
|
M1 = erlang:monotonic_time(), |
|
|
|
timer:sleep(N), |
|
|
|
M2 = erlang:monotonic_time(), |
|
|
|
Time = cvrTimeUnit(M2 - M1, native, nanosecond), |
|
|
|
Time = erlang:convert_time_unit(M2 - M1, native, nanosecond), |
|
|
|
io:format("IMY******************111 ~p~n", [Time]), |
|
|
|
|
|
|
|
S1 = erlang:system_time(nanosecond), |
|
|
|