From: Eleanor McHugh Date: 2008-06-27T17:36:39+09:00 Subject: Re: Performance improvement possible? On 27 Jun 2008, at 07:55, Philip Rhoades wrote: > Eleanor McHugh wrote: >> I'm surprised at the behaviour you're seeing so I ran a quick >> benchmark on what I believe to be an equivalent array handling >> problem with my laptop (OS X, Ruby 1.8.6-p111, Core 2 Duo 2GHz, 2GB >> RAM): >> require 'benchmark' >> include Benchmark >> bm(6) do |y| >> y.report("appending") { x = []; (1..20000000).each { |i| x << i } } >> y.report("nested creation") { x = Array.new(1000) >> { Array.new(1000) { Array.new(20, 0) } } } >> y.report("unrolling") { x.flatten.flatten.length } >> end >> user system total real >> appending 7.350000 0.100000 7.450000 ( 7.685458) >> nested creation 0.850000 0.000000 0.850000 ( 0.851341) >> unrolling 15.240000 0.280000 15.520000 ( 20.927189) >> which in each case is manipulating an array of 20,000,000 elements. >> This would be equivalent to processing 32000 files where each >> contained 625 occurrences of the 'k=' tag. > > I haven't used BM yet but I can't see how doing a benchmark on an > array helps? When I had an array it was slow, when I ditched the > array it was fast? Your experience runs counter to all of my experience, both in terms of several years of Ruby hacking and more generally in working on performance-optimisation for large data manipulation problems. Therefore being of a curious disposition I'd love to figure out why :) Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason