> > You have to stop spending so much time playing with all this bogus > > benchmarking :) > > It not bogus :) Its an example to find the best method for a project. >
And I'll reiterate more clearly. Benchmarking is *not* the tool to find the best method. The BEST method for a project is that method which is self evident and maintainable. ONLY AFTER you determine that you have missed your performance envelope, do you go back through your code using rakes and shovels and implements of destruction to find the slow parts. Early Optimization Is The Root of All Evil. > If you prefer I'll ask the question I was trying to answer with the > benchmark: > > Assuming you have an array of 0-15 elements is it quicker/more efficient to: > > 1) create a hash slice and use exists when checking for specific ones > or > 2) grep a regex out of the array when checking for specific ones > Both. Each one will 'win' in terms of total execution time for some set of conditions, none of which have been expressed in the problem. (For example, will the keys always be small integers? How complex will they be? This will have a tremendous impact on the performance of the match operator.) And, in fact, you yourself may not know a priori what the conditions will be - which is why I say (again because you really need to hear this): "Premature Optimization Is The Root of All Evil." Write your code so you can maintain it. The microseconds will take care of themselves. The programmers' time is orders of magnitude more costly than the computers', and your value is (hopefully!) increasing, while the cost of computational "oomph" is (thankfully) decreasing. Now, as to this specific question -- use whichever idiom you are more comfortable with. Furthermore, that is a tiny implementation detail -- in the Big Picture, it won't matter a gnats eyebrow. Finally, there were serious errors in your methodology in your original benchmark. It turns out the printing dominated the total execution time, such that the variance between the two different selection methods were pushed down into the noise. When I benchmarked using lists of 10 elements searching for five random members in the list, the exists-in-hash version was about 10 times faster for *JUST THE SELECTION OPERATION* than the grep-the-list version. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g Computer software consists of only two components: ones and zeros, in roughly equal proportions. All that is required is to sort them into the correct order. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>