To answer the question you asked; the breakpoint for performance comes around the 10 cases mark:

#! perl -slw use strict; use List::Util qw[ shuffle ]; use Benchmark qw[ cmpthese ]; our %dispatch = ( 'cybox:abcdef' => sub { 1; }, 'cybox:ghijkl' => sub { 1; }, 'cybox:mnopqr' => sub { 1; }, 'cybox:stuvwx' => sub { 1; }, 'cybox:123456' => sub { 1; }, 'cybox:234567' => sub { 1; }, 'cybox:345678' => sub { 1; }, 'cybox:456789' => sub { 1; }, 'cybox:567890' => sub { 1; }, 'cybox:000000' => sub { 1; }, ); our @k = map{ shuffle keys %dispatch } 1 .. 100; cmpthese -1, { a=>q[ for my $tname ( @k ) { $dispatch{ $tname }->(); } ], b=>q[ for my $tname ( @k ) { if( $tname eq 'cybox:abcdef' ) { 1; } elsif( $tname eq 'cybox:ghijkl' ) { 1; } elsif( $tname eq 'cybox:mnopqr' ) { 1; } elsif( $tname eq 'cybox:stuvwx' ) { 1; } elsif( $tname eq 'cybox:123456' ) { 1; } elsif( $tname eq 'cybox:234567' ) { 1; } elsif( $tname eq 'cybox:345678' ) { 1; } elsif( $tname eq 'cybox:456789' ) { 1; } elsif( $tname eq 'cybox:567890' ) { 1; } else { 1; } } ], }; __END__ C:\test>1149900 Rate b a b 1810/s -- -8% a 1967/s 9% -- C:\test>\Perl22\bin\perl.exe 1149900.pl Rate b a b 2370/s -- -18% a 2899/s 22% --

Though personally, I tend to gravitate to a dispatch hash when I get 4 or 5 cases or more because it makes for cleaner code.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: '100 elsif's vs hash of coderef's by BrowserUk
in thread '100 elsif's vs hash of coderef's by Wiggins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.