in reply to The speed of $_ versus a lexical
Try this:
I get a 2% speed difference; localising $_ makes the `my' version 4% faster.#!/usr/local/bin/perl -w use strict; use Benchmark; timethese(-2, { default => sub { $_="the quick brown fox"; s/brown/black/ }, my => sub { my $x="the quick brown fox"; $x =~ s/brown/black/ } });
Duplicating the string 10_000 times and performing global substitution makes the `my' version 11% faster.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re:x2 The speed of $_ versus a lexical
by grinder (Bishop) on Jul 19, 2001 at 14:58 UTC |