—Johnuse strict; use warnings; use Benchmark 'cmpthese'; my ($sym1, $sym2, $sym3, $sym4); sub strings { if ($_[0] eq "yes") { return 1; } elsif ($_[0] eq "no") { return 0; } elsif ($_[0] eq "maybe") { return 2; } elsif ($_[0] eq "foo") { return 3; } return undef; } sub numbers { if ($_[0] == 42) { return 1; } elsif ($_[0] == 33) { return 0; } elsif ($_[0] == 99) { return 2; } elsif ($_[0] == 69) { return 3; } return undef; } sub refs { if ($_[0] == \$sym1) { return 1; } elsif ($_[0] == \$sym2) { return 0; } elsif ($_[0] == \$sym3) { return 2; } elsif ($_[0] == \$sym4) { return 3; } return undef; } cmpthese (0, { 'strings 2' => sub { strings ("no") }, 'strings 4' => sub { strings ("notfound") }, 'numbers 2' => sub { numbers (33) }, 'numbers 4' => sub { numbers (99999) }, 'refs 2' => sub { refs (\$sym2); }, 'refs 4' => sub { refs (\&refs); } });
In reply to speed of comparisons of things by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |