Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^5: Unusual sorting requirements; comparing three implementations.

by BrowserUk (Pope)
on Oct 24, 2012 at 18:40 UTC ( #1000686=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Unusual sorting requirements; comparing three implementations.
in thread Unusual sorting requirements; comparing three implementations.

Not sure if your computer's architecture is radically different to mine or something, ...

The first difference I notice is that your fastest iterating solution -- 671/s -- is only half as fast as my fastest iterating solution -- 1100/s.

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

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:

package Person { sub new{ my $p = shift; bless { @_ }, $p } sub name{ $_[0]->{name } } sub title{ $_[0]->{title} } }

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

But mine are consistent:

C:\test>date /t & time/t && junk87 24/10/2012 19:39 Rate obvious subtle functional x obvious 189/s -- -16% -60% -83% subtle 226/s 19% -- -52% -80% functional 471/s 149% 109% -- -57% x 1101/s 482% 388% 134% --

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong


Comment on Re^5: Unusual sorting requirements; comparing three implementations.
Select or Download Code
Re^6: Unusual sorting requirements; comparing three implementations.
by tobyink (Abbot) on Oct 24, 2012 at 21:07 UTC

    "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...

                    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'
      Slow?! Ahem...

      Yes. Slow! (Be careful what you benchmark.):

      C:\test>type junk99.pl use Benchmark qw(cmpthese); { package Foo1; sub new { bless $_[1], $_[0] } sub foo { $_[0]{foo} } } { package Foo2; use Moo; has foo => (is => 'ro'); } our $foo1 = Foo1::->new({foo => 0}); our $foo2 = Foo2::->new({foo => 0}); cmpthese( -3, { plain_perl => q[ $foo1->foo for 1 .. 1000; ], moo => q[ $foo2->foo for 1 .. 1000; ], }); C:\test>junk99 Rate moo plain_perl moo 2065/s -- -13% plain_perl 2381/s 15% --

      (Think about it: Why would calling into C; unboxing perl vars to c vars ; and then calling the perl hash apis to access the hash fields (as C vars); and then wrapping those back into perl wrappers before returning; be quicker than a dedicated opcode -- written in C -- to access the hash?)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

        Running that exact script on my computer gives me...

                    Rate plain_perl        moo
        plain_perl 376/s         --       -62%
        moo        991/s       164%         --
        

        The difference may be the presence or absence of Class::XSAccessor which I've just noticed Moo uses if it's available, but falls back to pure Perl if it's not.

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

      Of course, we should really throw in a truly "plain perl" example as well:

      C:\test>type junk99.pl 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'); } our $foo1 = Foo1::->new({foo => 0}); our $foo2 = Foo2::->new({foo => 0}); our $foo3 = Foo3::->new({foo => 0}); our $foo4 = { foo => 0 }; cmpthese( -3, { OO_perl => q[ $foo1->foo for 1 .. 1000; ], moo => q[ $foo2->foo for 1 .. 1000; ], moose => q[ $foo3->foo for 1 .. 1000; ], plain_perl => q[ $foo4->{foo} for 1 .. 1000; ], }); C:\test>junk99 Rate moose moo OO_perl plain_perl moose 2004/s -- -3% -15% -74% moo 2068/s 3% -- -13% -73% OO_perl 2366/s 18% 14% -- -69% plain_perl 7624/s 280% 269% 222% --

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

        $ perl junk99 Rate moose OO_perl moo plain_perl moose 1007/s -- -16% -65% -74% OO_perl 1193/s 18% -- -58% -70% moo 2869/s 185% 141% -- -27% plain_perl 3944/s 292% 231% 37% -- $ perl -MClass::XSAccessor junk99 Rate moose OO_perl moo plain_perl moose 980/s -- -16% -67% -75% OO_perl 1167/s 19% -- -61% -70% moo 2991/s 205% 156% -- -23% plain_perl 3905/s 299% 235% 31% -- :) $ perl -MAutoXS::Accessor junk99 Rate moose OO_perl moo plain_perl moose 1007/s -- -15% -66% -74% OO_perl 1178/s 17% -- -61% -70% moo 2995/s 198% 154% -- -23% plain_perl 3905/s 288% 231% 30% -- $ perl -MDevel::VersionDump -MClass::XSAccessor junk99 Perl version: v5.14.1 on MSWin32 (C:\perl\5.14.1\bin\MSWin32-x86-multi +-thread\perl.exe) B - 1.29 Benchmark - 1.12 Carp - 1.26 Carp::Heavy - 1.26 Class::Load - 0.20 Class::Load::XS - 0.04 Class::MOP - 2.0603 Class::MOP::Attribute - 2.0603 Class::MOP::Class - 2.0603 Class::MOP::Class::Immutable::Trait - 2.0603 Class::MOP::Deprecated - 2.0603 Class::MOP::Instance - 2.0603 Class::MOP::Method - 2.0603 Class::MOP::Method::Accessor - 2.0603 Class::MOP::Method::Constructor - 2.0603 Class::MOP::Method::Generated - 2.0603 Class::MOP::Method::Inlined - 2.0603 Class::MOP::Method::Meta - 2.0603 Class::MOP::Method::Overload - 2.0603 Class::MOP::Method::Wrapped - 2.0603 Class::MOP::MiniTrait - 2.0603 Class::MOP::Mixin - 2.0603 Class::MOP::Mixin::AttributeCore - 2.0603 Class::MOP::Mixin::HasAttributes - 2.0603 Class::MOP::Mixin::HasMethods - 2.0603 Class::MOP::Module - 2.0603 Class::MOP::Object - 2.0603 Class::MOP::Package - 2.0603 Class::XSAccessor - 1.14 Class::XSAccessor::Heavy - 1.14 Config - Unknown Data::OptList - 0.107 Devel::GlobalDestruction - 0.05 Devel::VersionDump - 0.02 DynaLoader - 1.13 Eval::Closure - 0.08 Exporter - 5.66 Exporter::Heavy - 5.66 List::MoreUtils - 0.33 List::Util - 1.25 MRO::Compat - 0.11 Module::Implementation - 0.06 Module::Runtime - 0.013 Moo - 0.091007 Moo::HandleMoose - Unknown Moo::Object - Unknown Moo::_Utils - Unknown Moo::_mro - Unknown Moo::sification - Unknown Moose - 2.0603 Moose::Deprecated - 2.0603 Moose::Error::Default - 2.0603 Moose::Error::Util - Unknown Moose::Exporter - 2.0603 Moose::Meta::Attribute - 2.0603 Moose::Meta::Attribute::Native - 2.0603 Moose::Meta::Class - 2.0603 Moose::Meta::Class::Immutable::Trait - 2.0603 Moose::Meta::Instance - 2.0603 Moose::Meta::Method - 2.0603 Moose::Meta::Method::Accessor - 2.0603 Moose::Meta::Method::Augmented - 2.0603 Moose::Meta::Method::Constructor - 2.0603 Moose::Meta::Method::Delegation - 2.0603 Moose::Meta::Method::Destructor - 2.0603 Moose::Meta::Method::Meta - 2.0603 Moose::Meta::Method::Overridden - 2.0603 Moose::Meta::Mixin::AttributeCore - 2.0603 Moose::Meta::Object::Trait - 2.0603 Moose::Meta::Role - 2.0603 Moose::Meta::Role::Application - 2.0603 Moose::Meta::Role::Application::RoleSummation - 2.0603 Moose::Meta::Role::Application::ToClass - 2.0603 Moose::Meta::Role::Application::ToInstance - 2.0603 Moose::Meta::Role::Application::ToRole - 2.0603 Moose::Meta::Role::Attribute - 2.0603 Moose::Meta::Role::Composite - 2.0603 Moose::Meta::Role::Method - 2.0603 Moose::Meta::Role::Method::Conflicting - 2.0603 Moose::Meta::Role::Method::Required - 2.0603 Moose::Meta::TypeCoercion - 2.0603 Moose::Meta::TypeCoercion::Union - 2.0603 Moose::Meta::TypeConstraint - 2.0603 Moose::Meta::TypeConstraint::Class - 2.0603 Moose::Meta::TypeConstraint::DuckType - 2.0603 Moose::Meta::TypeConstraint::Enum - 2.0603 Moose::Meta::TypeConstraint::Parameterizable - 2.0603 Moose::Meta::TypeConstraint::Parameterized - 2.0603 Moose::Meta::TypeConstraint::Registry - 2.0603 Moose::Meta::TypeConstraint::Role - 2.0603 Moose::Meta::TypeConstraint::Union - 2.0603 Moose::Object - 2.0603 Moose::Util - 2.0603 Moose::Util::MetaRole - 2.0603 Moose::Util::TypeConstraints - 2.0603 Moose::Util::TypeConstraints::Builtins - 2.0603 Package::DeprecationManager - 0.13 Package::Stash - 0.33 Package::Stash::XS - 0.25 Params::Util - 1.07 Scalar::Util - 1.25 Sub::Defer - Unknown Sub::Exporter - 0.982 Sub::Install - 0.926 Sub::Name - 0.05 Time::HiRes - 1.9725 Try::Tiny - 0.11 XSLoader - 0.15 base - 2.18 constant - 1.21 if - 0.0601 metaclass - 2.0603 mro - 1.07 overload - 1.13 re - 0.18 strict - 1.04 strictures - 1.004001 vars - 1.02 warnings - 1.12 warnings::register - 1.02

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000686]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-09-23 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls