1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# utf8
use 5.8.1;
use strict;
use warnings;
use utf8;
package Bench::CAF;
use base qw(Class::Accessor::Fast);
__PACKAGE__->mk_accessors(qw(foo hoge));
package Bench::CAFr;
use base qw(Class::Accessor::Faster);
__PACKAGE__->mk_accessors(qw(foo hoge));
package Bench::CAL;
use Class::Accessor::Lite;
Class::Accessor::Lite->mk_accessors(qw(foo hoge));
sub new { bless {}, $_[0] }
package Bench::OTRW;
use Object::Tiny::RW qw(foo hoge);
package Bench::OS;
use base qw/Object::Simple/;
__PACKAGE__->attr("foo");
__PACKAGE__->attr("hoge");
package main;
use Benchmark qw(:all);
use Perl6::Say;
# use Data::Dumper;
sub confirm {
# say @_;
}
cmpthese(timethese( 100_000,
{
# Class::Accessor::Fast
caf => sub {
my $ac = Bench::CAF->new;
confirm($ac->foo("bar"));
confirm($ac->foo);
confirm($ac->hoge("fuga"));
},
# Class::Accessor::Faster
cafr => sub {
my $ac = Bench::CAFr->new;
confirm($ac->foo("bar"));
confirm($ac->foo);
confirm($ac->hoge("fuga"));
},
# Class::Accessor::Lite
cal => sub {
my $ac = Bench::CAL->new;
confirm($ac->foo("bar"));
confirm($ac->foo);
confirm($ac->hoge("fuga"));
},
# Object::Tiny
otrw => sub {
my $ac = Bench::OTRW->new;
confirm($ac->foo("bar"));
confirm($ac->foo);
confirm($ac->hoge("fuga"));
},
# Object::Simple
os => sub {
my $ac = Bench::OS->new;
confirm($ac->foo("bar"));
confirm($ac->foo);
confirm($ac->hoge("fuga"));
},
}));
|