in reply to Re: Matching First Character of Strings Efficiently
in thread Matching First Character of Strings Efficiently
Including 'expensive_function' in a benchmark means that you are mostly measuring how often that function gets called (which isn't what you asked for) and reduces the differences in the remaining items to the level of noise (which a worse benchmark).
I commented out the guts of expensive_function, shortened the names, added tye2 which does what I thought was the obvious optimization of pulling out the first char of $str_a at the top:
and got these results:'tye2' => sub { my $f = ord($str_a); for my $str_b ( @list ) { next if $f != ord( $str_b ); expensive_function ( $str_a, $str_b ); } },
Rate hb1 hb2 L~R3 BUk L~R2 dlrm L~R tye1 kvale ty +e2 hb1 46.5/s -- -35% -35% -38% -60% -62% -70% -73% -73% -7 +4% hb2 71.4/s 53% -- -0% -6% -38% -42% -54% -59% -59% -6 +1% L~R3 71.4/s 53% 0% -- -6% -38% -42% -54% -59% -59% -6 +1% BUk 75.7/s 63% 6% 6% -- -35% -39% -51% -56% -56% -5 +8% L~R2 116/s 149% 62% 62% 53% -- -6% -25% -33% -33% -3 +6% dlrm 124/s 166% 73% 73% 63% 7% -- -20% -28% -29% -3 +2% L~R 155/s 233% 117% 117% 105% 34% 25% -- -10% -11% -1 +4% tye1 172/s 270% 141% 141% 128% 48% 39% 11% -- -1% - +5% kvale 174/s 274% 143% 143% 130% 50% 41% 12% 1% -- - +4% tye2 181/s 289% 154% 154% 139% 56% 46% 17% 5% 4% +--
But I still consider such nano-optimization games to be more a waste than of value. (:
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^2: Matching First Character of Strings Efficiently (benchmarking)
by Limbic~Region (Chancellor) on Mar 15, 2004 at 22:58 UTC | |
by tye (Sage) on Mar 15, 2004 at 23:15 UTC | |
|
Re: Re^2: Matching First Character of Strings Efficiently (benchmarking)
by graff (Chancellor) on Mar 16, 2004 at 01:11 UTC | |
by tye (Sage) on Mar 16, 2004 at 02:21 UTC | |
by Aristotle (Chancellor) on Mar 16, 2004 at 03:21 UTC |