Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by BrowserUk (Patriarch)
on Oct 24, 2012 at 21:31 UTC ( [id://1000722]=note: print w/replies, xml ) Need Help??


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

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

  • Comment on Re^7: Unusual sorting requirements; comparing three implementations.
  • Download Code

Replies are listed 'Best First'.
Re^8: Unusual sorting requirements; comparing three implementations.
by tobyink (Canon) on Oct 24, 2012 at 21:53 UTC

    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'

      (Even for am Atom, your perl seems really, really slow. You have Moo running on your system at half the speed of Moose on mine?)

      I have that also, but still not seeing the benefit :

      C:\test>ppm-shell ppm 4.10 (ActivePerl 1007) Copyright (C) 2010 ActiveState Software Inc. All rights reserved. ppm> search Class::XSAccessor 1: Class-XSAccessor Generate fast XS accessors without runtime compilation Version: 1.13 Released: 2011-12-12 Author: Steffen Mueller <smueller@cpan.org> Provide: Class::XSAccessor version 1.13 Provide: Class::XSAccessor::Array version 1.13 Provide: Class::XSAccessor::Heavy version 1.13 Require: XSLoader Repo: ActiveState Package Repository CPAN: http://search.cpan.org/dist/Class-XSAccessor-1.13/ Installed: 1.13 (site) ppm> quit C:\test>perl -MClass::XSAccessor -E"say $Class::XSAccessor::VERSIO 1.13 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 1969/s -- -4% -17% -74% moo 2043/s 4% -- -14% -73% OO_perl 2382/s 21% 17% -- -69% plain_perl 7624/s 287% 273% 220% --

      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

      hr /

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-24 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found