- or download this
sub switch{ eval{ goto "case_$_[0]" } or goto default; }
for my $expr ( 1 .. 10, 'fred' ) {
switch( $expr ); {
- or download this
my $switch = sub { eval{ goto "case_$_[0]" } or goto default; };
for my $expr ( 1 .. 10, 'fred' ) {
$switch->( $expr ); {
- or download this
use strict;
use Benchmark;
...
}
},
} );
- or download this
Benchmark:
timing 50000 iterations of
...
if: 7 wallclock secs ( 5.41 usr + 0.00 sys = 5.41 CPU) @ 92
+42.14/s (n=50000)
switch: 43 wallclock secs (39.85 usr + 0.00 sys = 39.85 CPU) @ 12
+54.71/s (n=50000)