File Coverage

blib/lib/App/Benchmark/Accessors.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package App::Benchmark::Accessors;
2 3     3   149971 use strict;
  3         6  
  3         104  
3 3     3   18 use warnings;
  3         3  
  3         169  
4             our $VERSION = '2.00';
5              
6             #<<<
7             package # hide from PAUSE
8             WithMoose;
9 3     3   3353 use Moose;
  0            
  0            
10             has myattr => ( is => 'rw' );
11              
12             package # hide from PAUSE
13             WithMooseImmutable;
14             use Moose;
15             has myattr => ( is => 'rw' );
16             __PACKAGE__->meta->make_immutable;
17              
18             package # hide from PAUSE
19             WithMouse;
20             use Mouse;
21             has myattr => ( is => 'rw' );
22              
23             package # hide from PAUSE
24             WithMouseImmutable;
25             use Mouse;
26             has myattr => ( is => 'rw' );
27             __PACKAGE__->meta->make_immutable;
28              
29             package # hide from PAUSE
30             WithClassAccessor;
31             use parent qw(Class::Accessor);
32             __PACKAGE__->mk_accessors(qw/myattr/);
33              
34             package # hide from PAUSE
35             WithClassAccessorFast;
36             use parent qw(Class::Accessor::Fast);
37             __PACKAGE__->mk_accessors(qw/myattr/);
38              
39             package # hide from PAUSE
40             WithClassAccessorFastXS;
41             use parent qw(Class::Accessor::Fast::XS);
42             __PACKAGE__->mk_accessors(qw/myattr/);
43              
44             package # hide from PAUSE
45             WithClassXSAccessorCompat;
46             use parent qw(Class::XSAccessor::Compat);
47             __PACKAGE__->mk_accessors(qw/myattr/);
48              
49             package # hide from PAUSE
50             WithClassAccessorComplex;
51             use parent qw(Class::Accessor::Complex);
52             __PACKAGE__->mk_new->mk_scalar_accessors(qw/myattr/);
53              
54             package # hide from PAUSE
55             WithClassAccessorConstructor;
56             use parent qw(Class::Accessor::Constructor Class::Accessor::Complex);
57             __PACKAGE__->mk_constructor->mk_scalar_accessors(qw/myattr/);
58              
59             package # hide from PAUSE
60             WithClassAccessorClassy;
61             use Class::Accessor::Classy;
62             with 'new';
63             rw 'myattr';
64             no Class::Accessor::Classy;
65              
66             package # hide from PAUSE
67             WithClassAccessorLite;
68             use Class::Accessor::Lite new => 1, rw => [qw(myattr)];
69              
70             package # hide from PAUSE
71             WithMojo;
72             use parent qw(Mojo::Base);
73             __PACKAGE__->attr('myattr');
74              
75             package # hide from PAUSE
76             WithClassMethodMaker;
77             use Class::MethodMaker
78             [ scalar => [ qw/myattr/ ],
79             new => [ qw/-hash new/ ],
80             ];
81              
82             package # hide from PAUSE
83             WithObjectTiny;
84             use Object::Tiny qw/myattr/;
85              
86             package # hide from PAUSE
87             WithSpiffy;
88             use Spiffy -base;
89             field 'myattr';
90              
91             package # hide from PAUSE
92             WithClassSpiffy;
93             use Class::Spiffy -base;
94             field 'myattr';
95              
96             package # hide from PAUSE
97             WithAccessors;
98             use accessors qw(myattr);
99             sub new { bless {}, shift }
100              
101             package # hide from PAUSE
102             WithClassXSAccessor;
103             use Class::XSAccessor accessors => { myattr => 'myattr' };
104             sub new {
105             my $class = shift;
106             bless { @_ } => $class;
107             }
108              
109             package # hide from PAUSE
110             WithClassXSAccessorArray;
111             use Class::XSAccessor::Array accessors => { myattr => 0 };
112             sub new {
113             my $class = shift;
114             my %args = @_;
115             bless [ $args{myattr} ] => $class;
116             }
117              
118             package # hide from PAUSE
119             WithObjectTinyXS;
120             use Object::Tiny qw/myattr/;
121             use Class::XSAccessor accessors => { myattr => 'myattr' }, replace => 1;
122              
123             package # hide from PAUSE
124             WithRose;
125             use parent qw(Rose::Object);
126             use Rose::Object::MakeMethods::Generic(scalar => 'myattr');
127              
128             #package # hide from PAUSE
129             # WithBadgerClass;
130             #use Badger::Class
131             # base => 'Badger::Base',
132             # mutators => 'myattr';
133              
134             package # hide from PAUSE
135             WithRubyishAttribute;
136             use Rubyish::Attribute;
137             sub new { bless {}, shift }
138              
139             attr_accessor "myattr";
140             #>>>
141             1;
142              
143             __END__
144              
145             =head1 NAME
146              
147             App::Benchmark::Accessors - Benchmark accessor generators
148              
149             =head1 DESCRIPTION
150              
151             This distribution runs benchmarks on various accessor generators. The
152             following generators are being benchmarked:
153              
154             =over 4
155              
156             =item Moose
157              
158             mutable and immutable
159              
160             =item Mouse
161              
162             mutable and immutable
163              
164             =item Class::Accessor
165              
166             =item Class::Accessor::Fast
167              
168             =item Class::Accessor::Fast::XS
169              
170             =item Class::XSAccessor::Compat
171              
172             =item Class::Accessor::Complex
173              
174             =item Class::Accessor::Constructor
175              
176             =item Class::Accessor::Classy
177              
178             =item Class::Accessor::Lite
179              
180             =item Mojo::Base
181              
182             =item Class::MethodMaker
183              
184             =item Object::Tiny
185              
186             =item Spiffy
187              
188             =item Class::Spiffy
189              
190             =item C<accessors>
191              
192             =item Class::XSAccessor
193              
194             =item Class::XSAccessor::Array
195              
196             =item Object::Tiny
197              
198             =item Rose
199              
200             =item Rubyish::Attribute
201              
202             =back
203              
204             The benchmarks are being run as part of the test suite; see L<App::Benchmark>.
205             This way you can look at this distribution's CPAN testers page to see the
206             benchmark results on many different platforms and for many different perl
207             versions.
208              
209             The C<t/construction.t> file benchmarks object creation, C<t/get.t> benchmarks
210             getter methods and C<t/set.t> benchmarks setter methods.
211              
212             Not every benchmark is run on every module; for example, L<Object::Tiny>
213             doesn't create setter methods, and L<accessors> doesn't generate constructors.
214              
215             Each benchmark test file takes an optional numeric parameter that is used as
216             the number of iterations.
217              
218             It's probably a good idea not to read too much into these benchmarks; they
219             could be seen as micro-optimization. However, if you have a complex object
220             hierarchy and create lots of objects and run many many getters/setters on
221             them, they could help to save some time. But be sure to use L<Devel::NYTProf>
222             first to see where your real bottlenecks are.
223              
224             =head1 AUTHORS
225              
226             The following person is the author of all the files provided in
227             this distribution unless explicitly noted otherwise.
228              
229             Marcel Gruenauer C<< <marcel@cpan.org> >>, L<http://marcelgruenauer.com>
230              
231             =head1 COPYRIGHT AND LICENSE
232              
233             The following copyright notice applies to all the files provided in
234             this distribution, including binary files, unless explicitly noted
235             otherwise.
236              
237             This software is copyright (c) 2008 by Marcel Gruenauer.
238              
239             This is free software; you can redistribute it and/or modify it under
240             the same terms as the Perl 5 programming language system itself.
241