in reply to Re^2: Macro in perl code?
in thread Macro in perl code?
If your Benchmark shows your computer is able to perform an operation 3 million times pr. second, that's equivalent of a 1000 m2 highway sign saying: Don't optimize!$ cat 645237.pl use strict; use warnings; use Benchmark qw/ cmpthese /; use List::Util qw/ sum /; sub foo { my ($volume, $message) = @_; my @foo = ($volume .. $message); @foo = map { $_ ** 2 } @foo; return sum(@foo); } sub bar { my $volume = shift; my $message = shift; my @foo = ($volume .. $message); @foo = map { $_ ** 2 } @foo; return sum(@foo); } cmpthese(100_000, { shift => sub { foo(1, 100) }, inline => sub { bar(1, 100) }, } ); $ perl 645237.pl Rate inline shift inline 8396/s -- -0% shift 8403/s 0% --
Update: Changed code to supply arguments to functions as pointed out by bruceb3.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Macro in perl code?
by bruceb3 (Pilgrim) on Oct 16, 2007 at 21:27 UTC |