Skip to content

Commit

Permalink
Add two benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gfx committed Jan 12, 2010
1 parent ed7d3ac commit fabceb8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
35 changes: 35 additions & 0 deletions benchmark/method.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!perl -w

use strict;

use Benchmark qw(:all);

use Data::Clone;

BEGIN{
package Object;
sub new {
my $class = shift;
return bless { @_ }, $class;
}
package DC;
use Data::Clone qw(clone);
our @ISA = qw(Object);
}

my %args = (
foo => 42,
inc => { %INC },
);

my $o = DC->new(%args);

print "Method vs. Function:\n";
cmpthese -1 => {
'method' => sub{
my $x = $o->clone;
},
'function' => sub{
my $x = clone($o);
},
};
43 changes: 43 additions & 0 deletions benchmark/vs_fast.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!perl -w

use strict;

use Benchmark qw(:all);

use Clone::Fast ();
use Clone ();
use Data::Clone ();

my @array = (
[1 .. 10],
[1 .. 10]
);

print "ArrayRef:\n";
cmpthese -1 => {
'Clone' => sub{
my $x = Clone::clone(\@array);
},
'Clone::Fast' => sub{
my $x = Clone::Fast::clone(\@array);
},
'Data::Clone' => sub{
my $x = Data::Clone::clone(\@array);
},
};

my %hash = (
key => \@array,
);
print "HashRef:\n";
cmpthese -1 => {
'Clone' => sub{
my $x = Clone::clone(\%hash);
},
'Clone::Fast' => sub{
my $x = Clone::Fast::clone(\%hash);
},
'Data::Clone' => sub{
my $x = Data::Clone::clone(\%hash);
},
};

0 comments on commit fabceb8

Please sign in to comment.