drawde83 has asked for the wisdom of the Perl Monks concerning the following question:

I'm playing around with the benchmark module and I found out that the data is stored like so

($real, $user, $system, $children_user, $children_system, $iters)

My question is how do I get at these variables?
I could use timestr but I actually want to perform some calculations on the data rather than display it.

Replies are listed 'Best First'.
Re: getting at benchmarking data
by GrandFather (Saint) on Jun 23, 2006 at 22:47 UTC

    A little digging in Benchmark.pm shows that the values are returned as an array so you can:

    use strict; use warnings; use Benchmark qw(timethis cmpthese); my $str = 'The quick brown fox ' x 100; my $t = timethis (1000, sub {testSub ($str)}); print "\n@$t\n"; sub testSub { my $str = shift; my @matches = $str =~ /(\b.(?!ox))/g; }

    Prints:

    timethis 1000: 3 wallclock secs ( 2.38 usr + 0.00 sys = 2.38 CPU) @ + 421.05/s (n=1000) 3 2.375 0 0 0 1000

    DWIM is Perl's answer to Gödel
Re: getting at benchmarking data
by shmem (Chancellor) on Jun 23, 2006 at 22:55 UTC
    They are stored in the data structure returned by e.g. cmpthese timethese().
    use Data::Dumper; use Benchmark; $r = timethese ( 10157, foo => sub { func1(@args) }, bar => sub { $ref->(1,2,3) }, ); print Dumper($r) $VAR1 = { 'foo' => bless( [ 0, '0.0200000000000005', 0, 0, 0, 10157 ], 'Benchmark' ), 'bar' => bless( [ 4, '4.22', '0.01', 0, 0, 10157 ], 'Benchmark' ) };
    The anonymous array in each Benchmark object resembles ($real, $user, $system, $children_user, $children_system, $iters):
    $r->{bar}->[1] == 4.22
    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}