That's not precisely a fair test. How about this?
#!/usr/bin/perl use Benchmark 'cmpthese'; package Foo; sub new { my $class = shift; bless({@_}, $class); } sub foo { my ($self, @stuff) = @_; return map { $_.$_ } @stuff; } sub foo_pipe { my $self = shift; $self->foo(@_); } sub foo_my { my ($self,@stuff) = @_; $self->foo(@stuff); } sub foo_goto { goto &foo; } package main; my $foo = Foo->new(); my @stuff = 0..100; my @foo; cmpthese(500, { pipe => sub { $foo->foo_pipe(@foo=@stuff) }, goto => sub { $foo->foo_goto(@foo=@stuff) }, my => sub { $foo->foo_my(@foo=@stuff) }, });
This actually uses the entire array. The difference is rather minor, easily buried by the subroutine overhead.
Benchmark: timing 5000 iterations of goto, my, pipe... goto: 3 wallclock secs ( 2.96 usr + 0.00 sys = 2.96 CPU) @ 16 +89.19/s (n=5000) my: 4 wallclock secs ( 3.18 usr + 0.01 sys = 3.19 CPU) @ 15 +67.40/s (n=5000) pipe: 3 wallclock secs ( 2.89 usr + 0.00 sys = 2.89 CPU) @ 17 +30.10/s (n=5000) Rate my goto pipe my 1567/s -- -7% -9% goto 1689/s 8% -- -2% pipe 1730/s 10% 2% --

In reply to Re^10: How About A Better Benchmark? by tadman
in thread stoping and restarting a loop by mnlight

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.