Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

hanekomu (8123)

  (email not shown publicly)
AOL IM: hanekomu (Add Buddy, Send Message)

Go (Baduk) player and Perl hacker.

Journal of hanekomu (8123)

Saturday November 01, 2008
05:13 AM

Dissecting the Moose 3 - Benchmarking Accessor Generators

[ #37775 ]

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Can you include 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.
    • 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 and Class::MethodMaker as well. ( is not in the first benchmark because that tests object construction, mainly.)

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

  • 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

    • 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?