aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src/timer.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-04-20 15:32:22 +0200
committerBjörn Gustavsson <[email protected]>2015-04-20 15:33:44 +0200
commitd927209aa36fe370eb4ecf0a081923b0b951458b (patch)
tree0806c1a237b782523854d9b31ee2af84b5f0ab88 /lib/stdlib/src/timer.erl
parent6c3f8818f802164869519d58a538e70b1b8cc76c (diff)
downloadotp-d927209aa36fe370eb4ecf0a081923b0b951458b.tar.gz
otp-d927209aa36fe370eb4ecf0a081923b0b951458b.tar.bz2
otp-d927209aa36fe370eb4ecf0a081923b0b951458b.zip
timer: Use monotonic_time/0 in tc/1,2,3
Diffstat (limited to 'lib/stdlib/src/timer.erl')
-rw-r--r--lib/stdlib/src/timer.erl21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/stdlib/src/timer.erl b/lib/stdlib/src/timer.erl
index 19d803345e..c266177b4d 100644
--- a/lib/stdlib/src/timer.erl
+++ b/lib/stdlib/src/timer.erl
@@ -161,10 +161,11 @@ sleep(T) ->
Time :: integer(),
Value :: term().
tc(F) ->
- Before = os:timestamp(),
+ T1 = erlang:monotonic_time(),
Val = F(),
- After = os:timestamp(),
- {now_diff(After, Before), Val}.
+ T2 = erlang:monotonic_time(),
+ Time = erlang:convert_time_unit(T2 - T1, native, micro_seconds),
+ {Time, Val}.
%%
%% Measure the execution time (in microseconds) for Fun(Args).
@@ -175,10 +176,11 @@ tc(F) ->
Time :: integer(),
Value :: term().
tc(F, A) ->
- Before = os:timestamp(),
+ T1 = erlang:monotonic_time(),
Val = apply(F, A),
- After = os:timestamp(),
- {now_diff(After, Before), Val}.
+ T2 = erlang:monotonic_time(),
+ Time = erlang:convert_time_unit(T2 - T1, native, micro_seconds),
+ {Time, Val}.
%%
%% Measure the execution time (in microseconds) for an MFA.
@@ -190,10 +192,11 @@ tc(F, A) ->
Time :: integer(),
Value :: term().
tc(M, F, A) ->
- Before = os:timestamp(),
+ T1 = erlang:monotonic_time(),
Val = apply(M, F, A),
- After = os:timestamp(),
- {now_diff(After, Before), Val}.
+ T2 = erlang:monotonic_time(),
+ Time = erlang:convert_time_unit(T2 - T1, native, micro_seconds),
+ {Time, Val}.
%%
%% Calculate the time difference (in microseconds) of two