in reply to Re: Re^8: How about 450% greater performance
in thread stoping and restarting a loop
This actually uses the entire array. The difference is rather minor, easily buried by the subroutine overhead.#!/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) }, });
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% --
|
|---|