in reply to Succinct switch statement
And, by the way, is there an even shorter way to do print "\n"; ?Two characters shorter:
Update: And very, very slightly slower:print $/;
[keszler@tek perl]# cat test3.pl #!/usr/bin/perl -w use Benchmark; use strict; my $results = timethese( 1e4, { a => sub{print "\n" for(1..1e4);}, b => sub{print $/ for(1..1e4);}, } ); my $results2 = timethese( 1e4, { a2 => sub{print $/ for(1..1e4);}, b2 => sub{print "\n" for(1..1e4);}, } ); [keszler@tek perl]# ./test3.pl | grep -v '^$' Benchmark: timing 10000 iterations of a, b... a: 54 wallclock secs (33.83 usr + 0.92 sys = 34.75 CPU) @ 28 +7.77/s (n=10000) b: 54 wallclock secs (34.21 usr + 0.96 sys = 35.17 CPU) @ 28 +4.33/s (n=10000) Benchmark: timing 10000 iterations of a2, b2... a2: 54 wallclock secs (34.37 usr + 0.93 sys = 35.30 CPU) @ 28 +3.29/s (n=10000) b2: 54 wallclock secs (33.69 usr + 0.90 sys = 34.59 CPU) @ 28 +9.10/s (n=10000)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Succinct switch statement
by chromatic (Archbishop) on Oct 23, 2009 at 23:30 UTC |