From: Josh Cheek Date: 2009-08-20T03:45:22+09:00 Subject: Re: Confirm my Performance Test Against Java? --000e0cd5d0a27241e504718309c9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit My previous version would probably be better like this: start = Time.now puts "Starting to read file ..." puts "The number of tokens is: %d." % File.open(ARGV[0]){|f| f.inject(0){|a,l| a+l.split.length } } , "It took #{(Time.now - start) * 1000} ms" That way if the file is enormous, it prints the "starting to read file ..." immediately. On Wed, Aug 19, 2009 at 1:17 PM, Josh Cheek wrote: > A version of Mike Sassak's gist > > start = Time.now > printf "Starting to read file ...\nThe number of tokens is: %d.\nIt took > %.2f ms\n" , File.open(ARGV[0]){|f| f.inject(0){|a,l| a+l.split.length } } , > (Time.now - start) * 1000 > > I won't call it elegant, that seems subjective to me, but I do appreciate > brevity. > > > > On Wed, Aug 19, 2009 at 12:52 PM, Ben Christensen < > benjchristensen@gmail.com> wrote: > >> pharrington, in your response you stated: >> >> "as the code that happens is neither the most "elegant" *nor* fastest >> Ruby can do." >> >> Can you please provide me a re-write of the Ruby code I used that is >> elegant and fast so I can learn from you? >> >> I consider myself quite advanced in Java (14 years of experience there) >> but obviously do not have experience in Ruby for performance tuning and >> optimization. >> >> I would appreciate your demonstration of how to perform the task I have >> attempted in Ruby using an appropriate "Ruby" approach that achieves the >> highest performance possible and the "elegance" spoke of. >> >> Thank you. >> >> Ben >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > --000e0cd5d0a27241e504718309c9--