From: Stefan Rusterholz Date: 2007-05-24T07:15:25+09:00 Subject: Re: optimizing for speed - Array#each Mike Steiner wrote: > I ran the profiler on my program and it said that 51% of the time is > spent > in Array#each. Is there any way to speed this up (like using > Array#each_index perhaps)? > > And is there a quicker way to do a .gsub if I'm using just strings and > not a > regexp? > > By the way, the program compares 2 databases and determines which > records > have been inserted and deleted, and each database has about 15,000 > records > to compare. > > Mike Steiner No. I don't think you can speed up Array#each at all. What's far more promising is improving your algorithm in a way that it has to run less loops. You most likely have one or even several O(n^x) algorithms with x >= 2 in your app. Maybe you're not even aware. E.g. if you have an each with a select in the loop you're already in O(n^2) realm. The database comparison probably can be handled best with hashtables of the primary keys. Regards Stefan -- Posted via http://www.ruby-forum.com/.