From: "Florian Groß" Date: 2005-04-13T09:18:42+09:00 Subject: Re: Elapsed time -- tiny code snippet Hal Fulton wrote: > Here's a poor man's profiler -- only good for finding the > time in seconds it took to execute a code block. (I used > this today in a context where I was doing several operations > that invoked external programs and such.) > > I put it inside Time just for convenience. > > class Time > def self.elapse > raise "Need block" unless block_given? > t0 = Time.now > yield > Time.now - t0 > end > end > > secs = Time.elapse { do_something() } I'd suggest converting the times to floats (via .to_f) before subtracting -- it ought to be quite a bit more precise that way.