- or download this
cmpthese -3,{a=>q[@a = map $_*1, @a],b=>q[map $_*=1, @a],c=>q[$_*=1 fo
+r @a] };;
- or download this
timethese (10000000,{a=>q{map {1} @a},b=>q[map $_*=1, @a],c=>q[$_*=1 f
+or @a] });
- or download this
#! perl -slw
use strict;
...
a 3.46/s -- -68% -68%
c 10.7/s 208% -- -2%
b 10.8/s 213% 2% --
- or download this
timethese 10000, {
"idiomatic" => sub { my @array = 1..1000; $_ +=2 for @array;
+},
...
Benchmark: timing 10000 iterations of idiomatic, map...
idiomatic: 2 wallclock secs ( 1.52 usr + 0.00 sys = 1.52 CPU) @ 65
+96.31/s (n=10000)
map: 3 wallclock secs ( 3.06 usr + 0.00 sys = 3.06 CPU) @ 32
+64.77/s (n=10000)
- or download this
C:\test>IdiotsBench.pl
my @array = 1..1000;
...
Benchmark: timing 10000 iterations of idiomatic, map...
idiomatic: 1 wallclock secs ( 0.92 usr + 0.00 sys = 0.92 CPU) @ 10
+845.99/s (n=10000)
map: 2 wallclock secs ( 2.44 usr + 0.00 sys = 2.44 CPU) @ 41
+01.72/s (n=10000)
- or download this
C:\test>IdiotsBench.pl
timethese 10000, {
...
Benchmark: timing 10000 iterations of idiomatic, map...
idiomatic: 1 wallclock secs ( 0.95 usr + 0.00 sys = 0.95 CPU) @ 10
+493.18/s (n=10000)
map: 1 wallclock secs ( 0.95 usr + 0.00 sys = 0.95 CPU) @ 10
+493.18/s (n=10000)
- or download this
our @array2 = 1 .. 1000;
timethese 10000, {
...
Benchmark: timing 10000 iterations of idiomatic, map...
idiomatic: 1 wallclock secs ( 0.88 usr + 0.00 sys = 0.88 CPU) @ 11
+428.57/s (n=10000)
map: 1 wallclock secs ( 0.84 usr + 0.00 sys = 0.84 CPU) @ 11
+848.34/s (n=10000)