[RFC] a time interval class?

Robert Collins robertc at robertcollins.net
Wed Aug 15 06:53:32 BST 2007


On Wed, 2007-08-15 at 07:22 +0200, Marius Kruger wrote:
> hi,
> 
> this sounds cool but, ...


> Stopwatch sw = new Stopwatch(); //this automatically starts both
> timers
> sw.getDelta(); //returns and resets the delta timer 
> sw.printDelta(); //prints and resets the delta timer
> sw.printTotal(); //prints total time
> sw.reset(); //resets both timers.
> 
> The only reason I mention this is IMO your api requires to many calls
> or most uses. 

This seems unsubstantiated to me. 

> I suggest then that you:
> 1) don't require a .start() (let the constructor start it
> automatically)

This is bad style in lots of ways. Add to that that we need a
non-auto-starting timer for the benchmark suite.

> 2) add another method  .check()  (which returns and resets your delta
> timer)
> 3) add another method  .revert()  (which returns and resets your delta
> timer, but also reduces your total timer by the current delta) 

I think adding a reset() method to my api to allow duration.stop();
duration.start(); to be combined might be nice, though I don't have a
use for it.

What I don't like about your api is that its to my mind more confusing.

Also note that I was showing the full api in my example. I'd expect
typical code to do:

if debugging:
    duration = Duration()
    duration.start()
...
if debugging:
    mutter("... %s", ..., duration)
...
if debugging:
    mutter("... %s", ...., duration)

and thats all they need - they get a running total of the number of
seconds since the start() call.

Adding a second timer might be useful, but I think an easier thing to do
for the logging case is to just show the time since the last printout,
which is perhaps what you mean your code does.

As we have an object we can set state, so how about:
if debugging:
    duration = Duration()
    duration.start()
    duration.show_since_last_print(True)
...
if debugging:
    mutter("... %s", ..., duration)
...
if debugging:
    mutter("... %s", ...., duration)

where this would output strings like "4m2secs total, 25secs incremental"

> thats better for a lazy coder like me.
> it looks a bit crazy, so use what you like
> 
> hey you wanted comments

I appreciate them - thank you.

-Rob
-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070815/e9d7c743/attachment.pgp 


More information about the bazaar mailing list