diff options
author | Raimo Niskanen <[email protected]> | 2010-07-07 10:46:48 +0200 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2010-07-07 10:46:48 +0200 |
commit | a1a9aff12c1365dc155328410c5253d7495f757f (patch) | |
tree | b7b12d6f7cd38f94702bbc946d9671b9583d2738 /lib/stdlib/src | |
parent | 0aa94b3b70ae9bd99e23f99e51f08d694403fd21 (diff) | |
parent | 2cca6506bafedc5ebb720510151a98602133d8e5 (diff) | |
download | otp-a1a9aff12c1365dc155328410c5253d7495f757f.tar.gz otp-a1a9aff12c1365dc155328410c5253d7495f757f.tar.bz2 otp-a1a9aff12c1365dc155328410c5253d7495f757f.zip |
Merge branch 'cf/timer_tc' into dev
* cf/timer_tc:
Add timer:tc/2 to measure the elapsed time of anonymous functions
Conflicts:
lib/stdlib/doc/src/timer.xml
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/timer.erl | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/stdlib/src/timer.erl b/lib/stdlib/src/timer.erl index 6ee837c3e6..24e14caa69 100644 --- a/lib/stdlib/src/timer.erl +++ b/lib/stdlib/src/timer.erl @@ -22,7 +22,7 @@ send_after/3, send_after/2, exit_after/3, exit_after/2, kill_after/2, kill_after/1, apply_interval/4, send_interval/3, send_interval/2, - cancel/1, sleep/1, tc/3, now_diff/2, + cancel/1, sleep/1, tc/2, tc/3, now_diff/2, seconds/1, minutes/1, hours/1, hms/3]). -export([start_link/0, start/0, @@ -98,6 +98,17 @@ sleep(T) -> after T -> ok end. + +%% +%% Measure the execution time (in microseconds) for Fun(Args). +%% +-spec tc(function(), [_]) -> {time(), term()}. +tc(F, A) -> + Before = erlang:now(), + Val = (catch apply(F, A)), + After = erlang:now(), + {now_diff(After, Before), Val}. + %% %% Measure the execution time (in microseconds) for an MFA. %% |