Benchmark's cmpthese results - how to read

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Benchmark's cmpthese results - how to read

    Hello everyone,

    I have a two sets of code that I'd like to know which one is "fastest",
    so I turned to the Benchmark module to help solve the mystery. My code:

    #!/usr/bin/perl

    use warnings;
    use strict;
    use Benchmark qw( timethese cmpthese);

    my $string = '01/23/2004';
    my $x = 3;

    my $r = timethese( -5, {
    sbstr => sub{my $ko = substr($string, 0, 2)},
    regex => sub{my $ko = $string =~ /(\d{2})/},
    } );

    cmpthese $r;

    Returns:

    Benchmark: running regex, sbstr for at least 5 CPU seconds...
    regex: 4 wallclock secs ( 5.00 usr + 0.00 sys = 5.00 CPU) @
    309749.20/s (n=1548746)
    sbstr: 5 wallclock secs ( 5.28 usr + 0.00 sys = 5.28 CPU) @
    993059.28/s (n=5243353)
    Rate regex sbstr
    regex 309749/s -- -69%
    sbstr 993059/s 221% --

    This is great information, but a little confusing. After looking over
    the POD documentation for Benchmark, I think I understand, but would
    like clarification.

    If I understand correctly, of the 5 CPU seconds each subroutine was run
    the 'regex' subroutine took 4 wallclock seconds and the 'sbstr'
    subroutine took 5 wallclock seconds.

    What's confusing is everything after the word "seconds" for each
    subroutine...and the chart that has percentages in it. Does that chart
    mean that the 'regex' subroutine is 221% "faster" than the 'sbstr'
    subroutine?

    Also, what is the "translation" of '( 5.00 usr + 0.00 sys = 5.00 CPU)
    @ 309749.20/s (n=1548746)' and '( 5.28 usr + 0.00 sys = 5.28 CPU) @
    993059.28/s (n=5243353)'. I assume from the percentage chart that the
    '309749.20/s' and '993059.28/s' is the Rate, but what does that actually
    mean?

    Any help is appreciated,
    Kevin

    --
    Kevin Old <kold@kold.homelinux.com>

    Kevin Old Guest

  2. Similar Questions and Discussions

    1. formatting find results in results window or in savedfile
      I want a :beer; :-). I want to write an extension that will allow me to format the results returned from a find. I couldn't find anything in...
    2. Complex join = no results (for a query that shouldreturn results)
      I am trying to use a rather complex join that returns many results when the SQL server is queried directly, but returns no results when used on a...
    3. Sending search results to a results page..with asp
      Please help.. very :confused; Ive setup 4 dynamic drop down boxes which populate themselves from my database, this all works fine..The last box...
    4. Query results don't display properly in results table.IGNORE PREVIOUS
      :disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in...
    5. Query results don't display properly in results table.
      :disgust; I need to display the results of a query. The query runs properly. My problem is having specific results display in specific locations in...
  3. #2

    Default Re: Benchmark's cmpthese results - how to read

    On Sun, Jan 25, 2004 at 01:59:30PM -0500, Kevin Old (kold@kold.homelinux.com) wrote:
    > Hello everyone,
    >
    > I have a two sets of code that I'd like to know which one is "fastest",
    > so I turned to the Benchmark module to help solve the mystery. My code:
    >
    > #!/usr/bin/perl
    >
    > use warnings;
    > use strict;
    > use Benchmark qw( timethese cmpthese);
    >
    > my $string = '01/23/2004';
    > my $x = 3;
    >
    > my $r = timethese( -5, {
    > sbstr => sub{my $ko = substr($string, 0, 2)},
    > regex => sub{my $ko = $string =~ /(\d{2})/},
    > } );
    >
    > cmpthese $r;
    >
    > Returns:
    >
    > Benchmark: running regex, sbstr for at least 5 CPU seconds...
    > regex: 4 wallclock secs ( 5.00 usr + 0.00 sys = 5.00 CPU) @
    > 309749.20/s (n=1548746)
    > sbstr: 5 wallclock secs ( 5.28 usr + 0.00 sys = 5.28 CPU) @
    > 993059.28/s (n=5243353)
    > Rate regex sbstr
    > regex 309749/s -- -69%
    > sbstr 993059/s 221% --
    >
    > This is great information, but a little confusing. After looking over
    > the POD documentation for Benchmark, I think I understand, but would
    > like clarification.
    >
    > If I understand correctly, of the 5 CPU seconds each subroutine was run
    > the 'regex' subroutine took 4 wallclock seconds and the 'sbstr'
    > subroutine took 5 wallclock seconds.
    >
    Yes, although from what limited experience I have with the module, when
    your using "CPU seconds" the two "wall clock" figures will be very
    similar. Now if you change -

    "my $r = timethese( -5, {"
    to -
    "my $r = timethese( 1000, {"

    In other words do 1000 iterations of each subroutine. Then I think you
    will see a greater variance between "wall times."
    > What's confusing is everything after the word "seconds" for each
    > subroutine...and the chart that has percentages in it. Does that chart
    > mean that the 'regex' subroutine is 221% "faster" than the 'sbstr'
    > subroutine?
    >
    No, sbstr is 221% faster than regex
    regex is 69% slower than sbstr
    > Also, what is the "translation" of '( 5.00 usr + 0.00 sys = 5.00 CPU)
    > @ 309749.20/s (n=1548746)' and '( 5.28 usr + 0.00 sys = 5.28 CPU) @
    > 993059.28/s (n=5243353)'. I assume from the percentage chart that the
    > '309749.20/s' and '993059.28/s' is the Rate, but what does that actually
    > mean?
    "5.00 usr" refers to CPU percentage in user mode. "0.00 sys" refers to
    CPU percentage in system mode. Add them together and you get '5.00% total
    CPU time' for the first and 5.28% for the second.

    "993059.28/s" I think is the number of iterations the subroutine
    performed in a second. I'm not sure what "(n=5243353)" refers to for
    sure but it might be the actual number of iterations.

    Hope I got all that right. I'm sure someone will clear it up if I
    don't.
    Kent

    --
    Kenton Brede Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139