Issue #8640 has been updated by phluid61 (Matthew Kerwin).


rosenfeld (Rodrigo Rosenfeld Rosas) wrote:
> You're right, Matthew, although I'd appreciate some bookmark capabilities... But I understand it would be more costly since you'd need to malloc and free the struct everytime a bookmark is created...
> 
> Tanaka, I believe most people are interested in elapsed time rather than absolute time (Process.clock_gettime, System.currentTimeMillis(), etc). Having to process the elapsed time in the Ruby side is probably slower than doing the math on the C side, right?

clock_gettime allows you to choose which clock to get (on modern Linux, there are four), and if your relative timestamps are both Fixnums the difference between Ruby-land and C-land arithmetic is negligible.  See: https://github.com/phluid61/ruby-experiments/tree/master/gettime
----------------------------------------
Feature #8640: Add Time#elapsed to return nanoseconds since creation
https://bugs.ruby-lang.org/issues/8640#change-40586

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/