From: Maran Chandrasekar Date: 2009-02-13T16:19:33+09:00 Subject: Re: performance tips Joel VanderWerf wrote: > 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!} require 'benchmark' include Benchmark bm(7){|test| test.report('report : '){ lines = File.readlines('LOG/development.log').each {|l| l.chomp!} } } Output: user system total real report : 0.090000 0.030000 0.120000 ( 0.117250) Actually 'development.log' file 6MB size > do this: > > lines = File.open "test" do |f| > f.map {|line| line.chomp} >end require 'benchmark' include Benchmark bm(7){|test| test.report('report : '){ lines = File.open "LOG/development.log" do |f| f.map {|line| line.chomp} end } } Output : user system total real report : 0.240000 0.040000 0.280000 ( 0.272991) which is better? > > > That saves you from having the large string returned by #readlines. > > Sorry, no idea if these tips are collected somewhere. The rubygarden > wiki used to have them, IIRC, but it got killed by spam. -- Posted via http://www.ruby-forum.com/.