From: Robert Klemme Date: 2012-08-20T15:54:14+09:00 Subject: Re: case vs if-else On Mon, Aug 20, 2012 at 6:57 AM, Charles Hixson wrote: > The point was that because it's hard to tell what is fast and what is slow, > bad decisions are often made. The situation is not that bad. For example, we know that - from a certain number of entries on - it is much faster to use hash lookup than sequential lookup. Where exactly the point is from which on it's faster depends on the specific situation (hit rate, hash functions etc.). Whether a particular piece of code is a significant performance hog in a certain program can only be judged by measuring. But sill it does make sense to use a Hash as general lookup tool which generally will be quite good decision. > I was using my current habit of avoiding > regular expressions as an example of that. There you have a bad habit IMHO. Regular expressions are often faster in Ruby because they are implemented in C and do not need to create as many objects with GC overhead as any solution implemented in Ruby is likely to have. > I had heard that the regular > expression parser had been totally re-written, but because it would take a > lot of work to find out the details, I tend to cling to an habit which may > now be bad, even though it was once appropriate. You do not need to know too many details; you could just try it out and measure it, don't you think? Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/