On Wed, Jun 01, 2011 at 02:36:40PM +0100, Paul Makepeace wrote:
> On Tue, May 31, 2011 at 22:41, Nick Patch <[email protected]> wrote:
> > use Benchmark qw( cmpthese );
> >
> > cmpthese(-2, {
> > assign => sub { my $x = 'bar'; $x = "foo/$x" },
> > substr => sub { my $x = 'bar'; substr $x, 0, 0, 'foo/' },
> > lvalue => sub { my $x = 'bar'; substr($x, 0, 0) = 'foo/' },
> > });
>
> Oddly(?) join() is 20% faster than assignment:
>
> ...
> join => sub { my $x = 'bar'; $x = join('/', 'foo', 'bar') },
> oooscf => sub { my $x = 'bar'; $x = File::Spec->catfile($x, 'bar') },
> fnoscf => sub { my $x = 'bar'; $x = catfile($x, 'bar') },
You're not benchmarking the right behavior. In particular, your join sub
is not using $x in the call to join.
join => sub { my $x = 'bar'; $x = join('/', 'foo', $x) },
oooscf => sub { my $x = 'bar'; $x = File::Spec->catfile('foo', $x) },
fnoscf => sub { my $x = 'bar'; $x = catfile('foo', $x) },
Ronald
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm