in reply to Re: Not-so-Simple Switch statement
in thread Simple Switch statement

When doing such benchmarks, one should remember that printing is a very slow process. Even more, the time it takes is likely not very constant. So in order to get a real feel for how long the code-under-test really takes, you should do something fast and harmless, like setting a variable. So I replaced everything looking like
print STERR 'foo';
with
$out = 'foo';

I do get quite different results than yours. I always get the faster result for "HashSub" over "if", while with you, it's slower. Odd.

Replies are listed 'Best First'.
Re: 2Re: Not-so-Simple Switch statement
by NetWallah (Canon) on Sep 14, 2003 at 02:07 UTC
    I re-ran the tests too, replacing the "print STDERR" with an assignment.

    The "if" and "HashSub" methods speeds converge faster, with Hashsub becoming faster than "if" at a 22% match rate.

    The minor differences in results may have to do with OS and perl implementations. I'm running Activestate perl 5.8 under Windows XP.