cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:
This looks really weird (excuse the hacked OO - for demo purposes only :)
#!/usr/bin/perl use strict; use warnings; use Benchmark 'cmpthese'; my $self = bless [123], '::main'; cmpthese( 10000000, { normal => $self->a(), optimized => $self->b(), direct => $self->c(), }); exit(0); sub a { # old school accessor $self->get_value(); } sub b { # optimized accessor $self->get_value2(); } sub c { # fast and nasty, non oo accessor $self->[0]; } sub get_value { my $self = shift; return $self->[0]; } sub get_value2 { $_[0]->[0]; }
You would expect the direct method to benchmark fastest, but I got this:
Rate optimized direct normal optimized 12549020/s -- -1% -1% direct 12673267/s 1% -- 0% normal 12673267/s 1% 0% --
Am I missing something, or is that just plain weird?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected OO accessor benchmarks
by stvn (Monsignor) on Feb 09, 2007 at 20:08 UTC | |
by Fletch (Bishop) on Feb 09, 2007 at 20:10 UTC | |
by cLive ;-) (Prior) on Feb 09, 2007 at 20:23 UTC | |
by Fletch (Bishop) on Feb 09, 2007 at 20:42 UTC | |
by cLive ;-) (Prior) on Feb 10, 2007 at 00:55 UTC | |
| |
|
Re: Unexpected OO accessor benchmarks
by chromatic (Archbishop) on Feb 09, 2007 at 20:35 UTC | |
by eric256 (Parson) on Feb 10, 2007 at 02:24 UTC | |
by cLive ;-) (Prior) on Feb 10, 2007 at 01:08 UTC | |
by chromatic (Archbishop) on Feb 10, 2007 at 02:17 UTC |