From: Martin Hansen Date: 2010-09-01T20:35:52+09:00 Subject: Re: Speed issues iterating over chars Thanks Robert, The gsub solution seems to be reasonably efficient. > seq.gsub! /./ do |m| > scores[$`.length].ord - BASE_SOLEXA < cutoff ? m.downcase! : m > end But my original proposed naive loop is twice as fast: > scores.each_char do |score| > seq[i] = seq[i].downcase if score.ord - BASE_SOLEXA <= cutoff > i += 1 > end I dont really know how gsub and tr compares to the Perl equivalents speed wise - in Perl tr is precompiling a lookup table that is evil fast and the regex engine is also primed at compile time and runs extremely fast. I suspect that you need some C extension to go faster than this, but I don't really want to spend the time on that. I was exploring Inline C but that appears very fragile - I cannot even get the example from the cookbook up and running under Ruby 191/192. Looking at your last proposal I see three iterations where two are running narrow if loops. I have not testet it, but it looks suspicious. It is a shame that Ruby does not have build in bitwise operators for the String class allowing C speed masking. I have tried to get on the core mailing list to post this as a feature suggestion, but the ML form is stuffed. Cheers, Martin -- Posted via http://www.ruby-forum.com/.