"I seriously doubt my 3 y/o Core2Quad Q6600 @2.4GHz is twice as fast as your hardware."

I'm on a single core Intel Atom N270 clocked at 1.60 GHz.

"So the major difference probably comes down to the fact that I couldn't be bothered to install yet another slow-accessor constructor, so I manually code my Person Class"

Slow?! Ahem...

use v5.14; use Benchmark qw(cmpthese); package Foo1 { sub new { bless $_[1], $_[0] } sub foo { $_[0]{foo} } } package Foo2 { use Moo; has foo => (is => 'ro'); } package Foo3 { use Moose; has foo => (is => 'ro'); } # Note that I'm not even doing the make_immutable # secret sauce with Moose because that only affects # the speed of the constructor and destructor, not # accessors. my $foo1 = Foo1::->new({foo => 0}); my $foo2 = Foo2::->new({foo => 0}); my $foo3 = Foo3::->new({foo => 0}); cmpthese(1_000_000, { plain_perl => sub { $foo1->foo }, moo => sub { $foo2->foo }, moose => sub { $foo3->foo }, });
                Rate      moose plain_perl        moo
moose       304878/s         --       -18%       -73%
plain_perl  370370/s        21%         --       -67%
moo        1136364/s       273%       207%         --

Moo's accessors are stupidly fast because they use XS.

Even disabling XS via BEGIN { $ENV{MOO_XS_DISABLE} = 1 }, Moo's accessors are almost on par with the plain Perl version (about 7% slower).

As far as object construction goes, Moo is slower, but that's because Moo insists on some basic sanity checking as part of the constructor, which the plain Perl version shown above does not do.

But anyway, that could go some way to explaining:

"After that, why your results should be relatively different to mine I have no idea"

On my side I'm using Moo, so accessors are cheap calls. The functional implementation makes more calls to Person::name than your implementation, so slower accessors will cause it to drag.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re^6: Unusual sorting requirements; comparing three implementations. by tobyink
in thread Unusual sorting requirements; comparing three implementations. by tobyink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.