in reply to Re: Matching First Character of Strings Efficiently
in thread Matching First Character of Strings Efficiently
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Matching First Character of Strings Efficiently
by BrowserUk (Patriarch) on Mar 15, 2004 at 21:53 UTC | |
Sorry Limbic~Region, I got carried away with your "Only modify this line" (and had a brainfart too!). There is no point in looping over the array, that's why we put in a hash. It should have looked something like this.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"Think for yourself!" - Abigail | [reply] [d/l] |
by Limbic~Region (Chancellor) on Mar 15, 2004 at 22:35 UTC | |
| [reply] | |
by BrowserUk (Patriarch) on Mar 16, 2004 at 00:07 UTC | |
It requires a little work, but it is possible to add the loopup table to the benchmark. The results are that it shows benefits after 4 iterations and an order of magnitude by the time you get to 100 iterations. The lookup table will only need to be built once rather than everytime, so I've ensured that it gets built only on the first iteration of the benchmark. Whether this is legitimate will depend on whether your application requires processing of the array more than once. The breakpoint appears to occur at 4 iterations for the overhead of building the lookup to amortise out and give a clear winner. Of course, at this few iterations, there are lots of "Too few iterations" warnings. I added a check to ensure that the expensive function was called the same number of times in every case (the last line of each group of results below). This obviously requires the use of a positive iteration count rather than a negative one.
The modfied benchmark Read more... (3 kB)
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"Think for yourself!" - Abigail | [reply] [d/l] [select] |