Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Nice fast code, but does it return the right values? I checked with the orig mma routine, the my_mma routine and your reduce_mma routine. Using the same set of @nums, the results differ.
use Benchmark qw(:all :hireswallclock); my @nums = map {rand} 1 .. 10000; my $subs = { mma => sub { my @r = min_max_avg(\@nums) }, reduce_mma => sub { my @r = reduce_mma(\@nums) }, mymma => sub { my @r = my_mma(\@nums) } }; cmpthese(-1, $subs); $count = 1000; for my $sub (keys %$subs){ $t = timeit($count, $subs->{$sub}); print "$count loops of $sub:",timestr($t),"\n"; } for my $sub (keys %$subs){ print "$sub results:\n"; print (join ' ', &{$subs->{$sub}} , "\n"); } ##### Subs to test ###### __END__ $ perl benchmark.pl Rate mma mymma reduce_mma mma 86.3/s -- -49% -100% mymma 171/s 98% -- -100% reduce_mma 89229/s 103265% 52110% -- 1000 loops of reduce_mma:0.0114148 wallclock secs ( 0.00 usr + 0.00 s +ys = 0.00 CPU) 1000 loops of mma:12.0897 wallclock secs (12.05 usr + 0.01 sys = 12.0 +6 CPU) @ 82.91/s (n=1000) 1000 loops of mymma:5.98583 wallclock secs ( 5.97 usr + 0.00 sys = 5 +.97 CPU) @ 167.56/s (n=1000) reduce_mma results: 0.956444677504809 0.209810070551129 0.765697545177442 mma results: 0.000119859684559742 0.999992750475673 0.505291691541093 mymma results: 0.000119859684559742 0.999992750475673 0.505291691541093

In reply to Re^3: minimum, maximum and average of a list of numbers at the same time by codeacrobat
in thread minimum, maximum and average of a list of numbers at the same time by LucaPette

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found