[Issue 13724] std.datetime.timeIt

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Nov 13 06:53:04 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13724

--- Comment #4 from bearophile_hugs at eml.cc ---
(In reply to Steven Schveighoffer from comment #3)
> You're looking at it from the perspective that the time is the main thing
> you care about, i.e. you don't care about the return value, just the time it
> took.

If I want only the timing I return only the timing. But both this timeIt and
the Mathematica function return a pair of the result and the time to compute
it, because that's the most useful result and it's simple to handle and
remember. If you take an hour to compute something you don't want to repeat the
computation two times to have both result and timing.


> I look at it from the perspective that you want to time something that
> you are already using.
> 
> For example, if you have something like:
> 
> 37.fibonacci.foo();
> 
> Now, you want to keep your code the same, but get the time it took to do
> fibonacci, how do you do that with the tuple return?
> 
> With a ref parameter, you can do:
> 
> ulong timer;
> 37.fibonacci.timeIt(timer).foo();
> 
> Now I have the timer, and I don't have to mess with my call chain (much).
> 
> It also allows easier cumulative timing.

This is a different and more complex usage. It's interesting, but fails at
being very simple and short. So I am not sure.

Also "timer" in your example is an not-precisely typed variable (raw typed)
(and it's not a double).


> how do you do that with the tuple return?

In a functional language you often have "glue" that allows you to solve such
simple problems in a standard and simple way.

--


More information about the Digitalmars-d-bugs mailing list