From: Daniel Carrera Date: 2003-02-20T15:13:16+09:00 Subject: Re: optimization question On Thu, Feb 20, 2003 at 02:58:08PM +0900, Bulat Ziganshin wrote: > Hello Travis, > > Thursday, February 20, 2003, 1:53:14 AM, you wrote: > > TW> # This is ran about a million times > TW> h = Hash.new(0) > TW> data.scan(iptok).each do |tok| > TW> h[tok] += 1 > TW> end > > are you heard about "sort|uniq" idiom? I think that sorting is about as expensive as hashing. Here is a quick benchmark for 5,000 iterations: $ time ruby original_code.rb real 0m3.888s user 0m3.520s sys 0m0.020s $ time ruby your_code.rb real 0m3.453s user 0m3.140s sys 0m0.040s I still think that using C is a good idea. -- Daniel Carrera Graduate Teaching Assistant. Math Dept. University of Maryland. (301) 405-5137