From: Robert Klemme Date: 2009-02-13T17:33:33+09:00 Subject: Re: performance tips 2008/4/10 Joel VanderWerf : > Vince Forgetta wrote: >> >> Hi all, >> >> I've been using ruby for about 2 years, but only recently got around >> trying >> and learning it well. >> >> Is there some central repository I can get performance tips/discussions >> such >> as the one posted here: >> >> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/158212 > > Instead of: > > lines = File.readlines('sometextfile').each {|l| l.chomp!} > > do this: > > lines = File.open "test" do |f| > f.map {|line| line.chomp} > end > > That saves you from having the large string returned by #readlines. ??? I could have understood if you argued that your solution avoids traversing lines twice but this statement is plain wrong: File.readlines never returned a single String. http://www.ruby-doc.org/core/classes/IO.html#M002269 > Sorry, no idea if these tips are collected somewhere. The rubygarden wiki > used to have them, IIRC, but it got killed by spam. Many performance considerations can be found here. Searching for "Benchmark" should get you pretty far. :-) Apart from that IMHO there are two major rules of performance which can help eliminate many performance issues: 1. Do not do unnecessary work. 2. Carefully choose object life cycles. Kind regards robert -- remember.guy do |as, often| as.you_can - without end