Dissecting the Moose 3 - Benchmarking Accessor Generators

hanekomu on 2008-11-01T10:13:10

I wrote a small benchmarking program to compare the speeds of various accessor generators. They don't do much, just create an object while setting an accessor, then reading that accessor again, all for 100,000 times.

The following accessor generators are compared: Class::Accessor, Class::Accessor::Fast, Class::Accessor::Fast::XS, Class::Accessor::Complex, Class::Accessor::Constructor, Mouse, Moose, and immutable Moose.

Full post


accessors.pm

srezic on 2008-11-01T12:35:17

Can you include accessors.pm in the benchmark? In most perl configurations it is somewhat faster than Class::Accessor::Fast.
And it's also interesting which perl version on which OS the benchmark was running.

Re:accessors.pm

hanekomu on 2008-11-01T13:16:01

Thanks for the feedback!

I wrote the config in the first benchmark post, but maybe it was easy to miss as it is between the program and the results: 2.16 GHz MacBook with 2 GB RAM, Mac OS X 10.5.5, perl 5.8.8 (not the most recent one, I know).

After an update, the results now include accessors.pm and Class::MethodMaker as well. (accessors.pm is not in the first benchmark because that tests object construction, mainly.)

I cry shenanigans!

Alias on 2008-11-02T02:48:20

You forgot the fastest of them all, Object::Tiny.

Re:I cry shenanigans!

hanekomu on 2008-11-02T08:51:04

Sorry; I'll add it as soon as I get around to it.

Thanks!

Re:I cry shenanigans!

hanekomu on 2008-11-02T13:18:42

Done; now includes Object::Tiny, Spiffy, Class::Spiffy and direct hash access. See http://hanekomu.at/blog

I realised one more you forgot

Alias on 2008-11-02T19:22:24

It seems to me to be slightly odd that Object::Tiny is faster than Class::Accessor::Fast::XS, since the latter is a blatant copy/paste job from Class::XSAccessor, which I _KNOW_ is faster than Object::Tiny.

So between Stephen and I we propose a new "King" for your competition, which we can tentatively call "Object::Tiny::XS" and is Object::Tiny enhanced by Class::XSAccessor.

use Object::Tiny qw/myattr/;
use Class::XSAccessor getters => { myattr => 'myattr' };

That should combine the fastest part of Object::Tiny with the fastest available XS getter, resulting in an unbeatable contender.

Re:I realised one more you forgot

hanekomu on 2008-11-04T13:41:56

I've added it and others and repackaged the whole thing - see this blog entry

Badger?

stu42j on 2008-11-03T16:26:46

How about Badger?

http://search.cpan.org/perldoc?Badger

Re:Badger?

hanekomu on 2008-11-04T13:45:42

I'd like to add benchmarks for Badger but am not sure which of the many options to use. Use Badger::Class? accessors() or mutators()? Where do I get new() from? Foo->new(myattr => 27) seems to set $obj->{conf}{myattr}, but $obj->myattr() seems to want to read from $obj->{myattr}. Badger seems to have a lot of features, and maybe I'm too dense to pick out a simple example...

Could you please show me a simple example along the lines of the existing benchmarks how I should benchmark Badger?