From: Austin Ziegler Date: 2016-03-15T14:07:44-04:00 Subject: [ruby-core:74346] Re: [Ruby trunk Feature#12173] `Time#till_now` --===============1112387004== Content-Type: multipart/alternative; boundary=047d7bdc12b04b04ae052e1a47f7 --047d7bdc12b04b04ae052e1a47f7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I=E2=80=99ll do a bit of bike shedding on this and want to address one comm= ent by Benoit Daloze. What if we make it so that the method is just #until and accepts an optional parameter? ~~~RUBY class Time def until(recent =3D self.class.now) recent - self end end ~~~ As Benoit suggests, if you=E2=80=99re doing benchmarks, you=E2=80=99re goin= g to want something more reliable=E2=80=94but from a user interaction perspective, I = think that this is very useful. On Tue, Mar 15, 2016 at 4:21 AM, wrote: > Issue #12173 has been updated by Benoit Daloze. > > > Tsuyoshi Sawada wrote: > > It is very frequent to have a time instance: > > > > ~~~RUBY > > t =3D 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 =3D 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 =3D Time.now > # some heavy operation > puts "It took #{t.till_now} secs." > > > > -- > https://bugs.ruby-lang.org/ > > Unsubscribe: > > --=20 Austin Ziegler =E2=80=A2 halostatue@gmail.com =E2=80=A2 austin@halostatue.c= a http://www.halostatue.ca/ =E2=80=A2 http://twitter.com/halostatue --047d7bdc12b04b04ae052e1a47f7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I=E2=80=99ll do a bit of=C2=A0bike shedding on this a= nd want to address one comment by Benoit Daloze.

W= hat if we make it so that the method is just #until and accepts an optional= parameter?

~~~RUBY
class Time
=C2=A0 def until(recent =3D self.class.now)
=C2=A0 =C2=A0 recent= - self
=C2=A0 end
end
~~~

As Benoit suggests, if you=E2=80=99re doing benchmarks, you=E2=80=99re g= oing to want something more reliable=E2=80=94but from a user interaction pe= rspective, I think that this is very useful.


On Tue, Mar 15, 2016 at 4= :21 AM, <eregontp@gmail.com> wrote:
Issue #12173 has been updated by Benoit Daloze.


Tsuyoshi Sawada wrote:
> It is very frequent to have a time instance:
>
> ~~~RUBY
> t =3D 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)` sh= ould 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-5= 7459

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

~~~RUBY
t =3D Time.now
~~~

and then after some operations, do:

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

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

~~~RUBY
class Time
=C2=A0 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 =3D 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=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-core>



--
=
Austin Ziegler =E2=80=A2 halostatue@gmail.com =E2=80=A2 <= a href=3D"mailto:austin@halostatue.ca" target=3D"_blank">austin@halostatue.= ca
http://ww= w.halostatue.ca/ =E2=80=A2 http://twitter.com/halostatue
--047d7bdc12b04b04ae052e1a47f7-- --===============1112387004== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============1112387004==--