Issue #12173 has been updated by Benoit Daloze.


Tsuyoshi Sawada wrote:
> It is very frequent to have a time instance:
> 
> ~~~RUBY
> t = Time.now
> ~~~
> 
> and then after some operations, do:
> 
> ~~~RUBY
> Time.now - t
> ~~~

This seems fairly related to #8640.
Just a note: the Time.now - t is typically not what you want if you want to benchmark some piece of code.
A monotonic clock like `Process.clock_gettime(Process::CLOCK_MONOTONIC)` should be used instead (I know, it's a bit lengthy).
Or well if you can require 'benchmark' then it's just Benchmark.realtime { ... }.

----------------------------------------
Feature #12173: `Time#till_now`
https://bugs.ruby-lang.org/issues/12173#change-57459

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
It is very frequent to have a time instance:

~~~RUBY
t = Time.now
~~~

and then after some operations, do:

~~~RUBY
Time.now - t
~~~

I propose `Time#till_now`, which is equivalent to:

~~~RUBY
class Time
  def till_now; self.class.now - self end
end
~~~

and similar methods can perhaps be defined on `Date` and `DateTime` classes as well. Another candidate for the method name is `until_now`.

Then we can do:

~~~RUBY
t = Time.now
# some heavy operation
puts "It took #{t.till_now} secs."



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>