From: David Garamond Date: 2004-12-28T22:21:39+09:00 Subject: Re: help on making ruby code faster Stefan Schmiedl wrote: > On Tue, 28 Dec 2004 20:41:57 +0900, > David Garamond wrote: > >>Benchmark.measure shows that, on my box, I can do around 2000-2500 of >>roundtrip conversions per second, which is not too bad. But I wonder if >>it can be made more efficient. The Ruby profiler shows the top 4 methods: > > I'm not sure on the effects it will have, but try extracting > the constants from your often-called methods. You're repeatedly > creating "the same objects" which might slow you down due to > unnecessary garbage collection. By constants, do you mean literal constants like '0-9a-z', 'a-z0-9', and 'a' in the code below? def to_base36 self.to_i.to_s(36).tr('0-9a-z', 'a-z0-9').rjust(25, 'a') end Can't Ruby currently optimize those? I frankly don't want to have to do those kinds of optimization myself :-( Regards, dave