Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl

Idiom #125 Measure function call duration

measure the duration t, in nanoseconds, of a call to the function foo. Print this duration.

use Benchmark qw(:hireswallclock timediff);
sub foo {};
my $start = Benchmark->new;
foo;
my $t = timediff(Benchmark->new, $start)->[0] * 10**9; 
(time (foo))

time prints time elapsed, but in ms

New implementation...
< >
JPSII