use strict; #use warnings; #no warnings 'redefine'; #use Smart::Comments::JSON '##'; use Benchmark qw(:all) ; use Class::Accessor; use Class::Accessor::Fast; use Class::XSAccessor; use Moose; my $RANGE = 99999999; my $count = 3000; my $ENABLE_UNUSE = 0; sub unuse { my $pat = shift; return if !$ENABLE_UNUSE; for my $key (keys %INC) { if ($key =~ $pat) { #warn $key; delete $INC{$key}; } } } my $moose_code = sub { unuse(qr/^Moose/); my $rand = int rand $RANGE; eval qq{ package FooA$rand; use Moose; has x=>(is=>'ro'); has y=>(is=>'ro'); }; die $@ if $@; }; my $fast_code = sub { unuse(qr/^Class\//); my $rand = int rand $RANGE; eval qq{ package FooB$rand; use base "Class::Accessor::Fast"; __PACKAGE__->mk_accessors(qw/x y/); }; die $@ if $@; }; my $accessor_code = sub { unuse(qr/^Class\//); my $rand = int rand $RANGE; eval qq{ package FooC$rand; use base "Class::Accessor"; __PACKAGE__->mk_accessors(qw/x y/); }; die $@ if $@; }; my $xs_code = sub { unuse(qr/^Class\//); my $rand = int rand $RANGE; eval qq( package FooD$rand; use Class::XSAccessor accessors => { x => "x", y => "y"}, replace => 1; ); die $@ if $@; }; ## $moose_code ## $fast_code ## $accessor_code ## $xs_code cmpthese($count, { 'Moose' => $moose_code, 'Class::Accessor' => $accessor_code, 'Class::Accessor::Fast' => $fast_code, 'Class::XSAccessor' => $xs_code, });