Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^6: Write code diferently

by Laurent_R (Canon)
on Aug 26, 2013 at 20:09 UTC ( [id://1051005]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    use Benchmark;
    
    my @a = 1..1000000;
    timethese (10000000,{a=>q{map {1} @a},b=>q[map $_*=1, @a],c=>q[$_*=1 f
    +or @a] });
    
  2. or download this
             a:  1 wallclock secs ( 0.75 usr +  0.00 sys =  0.75 CPU) @ 13
    +368983.96/s (n=10000000)
             b:  0 wallclock secs ( 0.75 usr +  0.00 sys =  0.75 CPU) @ 13
    +368983.96/s (n=10000000)
             c:  2 wallclock secs ( 1.70 usr +  0.00 sys =  1.70 CPU) @ 58
    +78894.77/s (n=10000000)
    
  3. or download this
    use strict;
    use warnings;
    use Benchmark;
    ...
                    "idiomatic" => sub { my @array = 1..1000; $_ +=2 for @
    +array; },
                    "map"                  => sub { my @array = 1..1000; m
    +ap { $_ +=2;}  @array; }
    } );
    
  4. or download this
    Benchmark: timing 10000 iterations of idiomatic, map...
    idiomatic:  3 wallclock secs ( 3.25 usr +  0.01 sys =  3.26 CPU) @ 306
    +7.48/s (n=10000)
           map:  6 wallclock secs ( 5.91 usr +  0.01 sys =  5.92 CPU) @ 16
    +89.19/s (n=10000)
    
  5. or download this
     idiomatic:  2 wallclock secs ( 1.59 usr +  0.00 sys =  1.59 CPU) @ 62
    +8.93/s (n=10000)
           map:  3 wallclock secs ( 2.88 usr +  0.00 sys =  2.88 CPU) @ 34
    +7.22/s (n=10000)
    
  6. or download this
    Benchmark: timing 10000 iterations of idiomatic, map...
    idiomatic:  2 wallclock secs ( 0.89 usr +  0.00 sys =  0.89 CPU) @ 112
    +35.96/s (n=10000)
           map:  3 wallclock secs ( 1.70 usr +  0.00 sys =  1.70 CPU) @ 58
    +82.35/s (n=10000)
    
  7. or download this
    Benchmark: timing 10000 iterations of idiomatic, map...
     idiomatic:  1 wallclock secs ( 1.25 usr +  0.00 sys =  1.25 CPU) @ 80
    +12.82/s (n=10000)
           map:  3 wallclock secs ( 2.31 usr +  0.00 sys =  2.31 CPU) @ 43
    +30.88/s (n=10000)
    
  8. or download this
    Benchmark: timing 10000 iterations of idiomatic, map...
     idiomatic:  1 wallclock secs ( 1.01 usr +  0.00 sys =  1.01 CPU) @ 98
    +61.93/s (n=10000)
           map:  2 wallclock secs ( 2.08 usr +  0.00 sys =  2.08 CPU) @ 48
    +19.28/s (n=10000)
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1051005]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found