Skip to content

Instantly share code, notes, and snippets.

@zigorou
Created April 7, 2010 15:40
Show Gist options
  • Select an option

  • Save zigorou/359027 to your computer and use it in GitHub Desktop.

Select an option

Save zigorou/359027 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
package Foo;
use parent qw(Class::Accessor::Fast);
__PACKAGE__->mk_accessors(qw/name/);
package Bar;
use parent qw(Class::Accessor::Grouped);
__PACKAGE__->mk_group_accessors( 'simple' => qw/name/ );
sub new {
bless $_[1] || +{} => $_[0];
}
package Baz;
use Moose;
has 'name' => (
is => 'rw'
);
__PACKAGE__->meta->make_immutable;
package Hoge;
use Mouse;
has 'name' => (
is => 'rw'
);
__PACKAGE__->meta->make_immutable;
package main;
use Benchmark qw(cmpthese);
my ( $foo, $bar, $baz, $hoge ) = ( Foo->new, Bar->new, Baz->new, Hoge->new );
cmpthese(
500000 => +{
caf => sub {
$foo->name("hidek");
$foo->name;
},
cag => sub {
$bar->name("hidek");
$bar->name;
},
moose => sub {
$baz->name("hidek");
$baz->name;
},
mouse => sub {
$hoge->name("hidek");
$hoge->name;
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment