>>>>> "PM" == Paul Makepeace <paul.makepe...@realprogrammers.com> writes:
PM> On Tue, May 31, 2011 at 22:41, Nick Patch <n...@atemoya.net> 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/' }, >> }); PM> Oddly(?) join() is 20% faster than assignment: PM> ... PM> join => sub { my $x = 'bar'; $x = join('/', 'foo', 'bar') }, PM> oooscf => sub { my $x = 'bar'; $x = File::Spec->catfile($x, 'bar') }, PM> fnoscf => sub { my $x = 'bar'; $x = catfile($x, 'bar') }, PM> Rate fnoscf oooscf lvalue assign join substr PM> fnoscf 146161/s -- -6% -94% -95% -96% -97% PM> oooscf 155614/s 6% -- -93% -95% -96% -97% PM> lvalue 2307768/s 1479% 1383% -- -28% -41% -59% PM> assign 3190698/s 2083% 1950% 38% -- -18% -43% PM> join 3912592/s 2577% 2414% 70% 23% -- -30% PM> substr 5609155/s 3738% 3505% 143% 76% 43% -- my view would be join has a very fast string build up. it could preallocate the length of the string so no extra copying is needed. assign is really plain interpolation but assigning back to a var used in it. i wonder if assigning to another var would speed it up a bit. perl may not be smart enough in that case to optimize but join can do that. same for 4 arg substr. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- _______________________________________________ Boston-pm mailing list Boston-pm@mail.pm.org http://mail.pm.org/mailman/listinfo/boston-pm