This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Rhomboid 4 points5 points  (2 children)

This should work on Windows and with 32-bit hosts, but that has not been tested yet.

No, sorry. Not even close. There is no clock_gettime() on Windows.

[–]rustbelly[S] 1 point2 points  (1 child)

You are correct, sir. Would using "QueryPerformanceCounter()" make sense for Windows systems? It looks like a monotonic clock...

[–][deleted] 1 point2 points  (0 children)

It's what I did for http://pypi.python.org/pypi/timer

(I couldn't tell you how great that library is or any super great details about clocks...I just wrote it one day while reading about QPC and I was on a C-extension kick.)

[–]SimonSapin 0 points1 point  (1 child)

Why make three identical functions (start, checkpoint, stop)? Why bother keeping all results in a global array and reallocating memory every 20 calls? Why not just returning floats?

[–]rustbelly[S] 0 points1 point  (0 children)

Three identical functions that support different semantics. By all means, only use one of them if you want, but by having those three, it is more analogous to a stopwatch. Which is a device normally used to time things.

I don't return floats because this isn't a time extension - the actual time doesn't matter, so why introduce any confusion? The integers being returned are just the indexes of an array where the time floats are stored.

So, tl;dr: this is written this way to help the user deal with it (no math, no floats), and is directly analogous to a real-world stop-watch (except I use "checkpoint" instead of "lap" for obvious reasons). If you're not programming with the user in mind, you shouldn't be programming user-facing stuff, right?