From: "phluid61 (Matthew Kerwin)" Date: 2013-07-18T07:59:34+09:00 Subject: [ruby-core:56068] [CommonRuby - Feature #8640] Add Time#elapsed to return nanoseconds since creation Issue #8640 has been updated by phluid61 (Matthew Kerwin). tenderlovemaking (Aaron Patterson) wrote: > On Wed, Jul 17, 2013 at 01:04:37PM +0900, phluid61 (Matthew Kerwin) wrote: > > Since the discussion has moved towards defining two separate methods {#elapsed => (float)s and #elapsed_nanoseconds => (int)ns} I do prefer a keyword argument {in: :nanoseconds}. Sorry for wavering back and forth on the issue so noisily. > > I don't care if a method exists that has kw args, but I would not use > it. The things we need to time in Rails are fairly fast (say 200ms on > the slow side) and happen frequently, which means that object > allocations matter. A kwarg method will end up allocating a hash on > every call. > > If someone else wants to make a method with kwargs, I think that's > great, but it's not what I'm pushing for here. My point is to reduce > object allocations. :-) > In that case, would #8096 be a better proposal? Since that one doesn't even allocate a Time object. ---------------------------------------- Feature #8640: Add Time#elapsed to return nanoseconds since creation https://bugs.ruby-lang.org/issues/8640#change-40555 Author: tenderlovemaking (Aaron Patterson) Status: Open Priority: Normal Assignee: Category: Target version: Hi, We time many things in Rails (and so does lots of other code), and I've found that we spend lots of time allocating and subtracting time objects. For example: start = Time.now ## do stuff we want to time finish = Time.now - start It would be nice if we could just create one time object and grab the nanoseconds elapsed since the time object was created like so: start = Time.now ## do stuff we want to time finished = start.elapsed # => nanoseconds elapsed. I've attached a patch that implements this feature. -- http://bugs.ruby-lang.org/