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?)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Unusual sorting requirements; comparing three implementations.
by tobyink (Canon) on Oct 24, 2012 at 21:53 UTC | |
by BrowserUk (Patriarch) on Oct 24, 2012 at 22:04 UTC |