Created
August 17, 2011 15:41
-
-
Save mix3/1151814 to your computer and use it in GitHub Desktop.
fwbench.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Class; | |
sub new { | |
my $class = shift; | |
my $self = shift || {}; | |
return bless $self, $class; | |
} | |
sub add { | |
my $self = shift; | |
return $_[0] + $_[1]; | |
} | |
1; | |
package main; | |
use Benchmark qw(cmpthese timethese); | |
sub add { | |
return $_[0] + $_[1]; | |
} | |
my $instance = Class->new; | |
cmpthese timethese(100000, { | |
class => sub { | |
my $o = Class->new; | |
$o->add(1,1); | |
}, | |
instance => sub { | |
$instance->add(1,1); | |
}, | |
method => sub { | |
&add(1,1); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ perl fwbench.pl