From: ts Date: 2000-12-28T19:53:05+09:00 Subject: [ruby-talk:8164] Re: speedup of anagram finder >>>>> "J" == Joseph McDonald writes: J> % head -20000 /usr/share/dict/words | ./anagrams2.rb J> user system total real J> keys 5.148438 0.023438 5.171875 ( 5.219981) J> each_byte 1.835938 0.015625 1.851562 ( 1.862386) I was very surprised by this result, so I've asked Joseph McDonald to send me, in a private email, its test. If you take its source and run multiple times "keys" and "each_byte", you'll see something like this : pigeon% head -20000 words | /usr/bin/ruby anagrams2.rb user system total real keys 3.900000 0.020000 3.920000 ( 3.922335) each_byte 1.600000 0.000000 1.600000 ( 1.599187) keys 2.550000 0.000000 2.550000 ( 2.550042) each_byte 1.600000 0.000000 1.600000 ( 1.597049) keys 2.550000 0.000000 2.550000 ( 2.550949) each_byte 1.590000 0.000000 1.590000 ( 1.595726) pigeon% See the unusual result 3.900000 for the first run of "keys" (I think that it's the result of the allocation of memory, after ruby can re-use the memory previously allocated) Be carefull with benchmark, especially for the first result. Someone can send me a script where it's possible to see a difference *significative* between an #each and a #for ? Guy Decoux