libgit2/libgit2 — pull request #1862 by phkelley (2013-09-21 15:20:45+00:00)
Title: Add stopwatch APIs for timing

There has been a lot of discussion in #1412 about how best to do timing. I wanted to present what I think is a simple API for measuring elapsed time - the stopwatch concept.

The caller starts by allocating a `git_stopwatch` on the stack. The contents of a `git_stopwatch` are platform-specific and are intended to be opaque to the caller. The `git_stopwatch_start` function starts the stopwatch by capturing the current time. The `git_stopwatch_query` function takes a second sample and then returns the amount of elapsed time since the stopwatch was started. The elapsed time is returned as a `double`, in seconds.

Stopwatches are restartable -- just call `git_stopwatch_start` again. You can also query a single stopwatch multiple times. I like this better than the `git__timer` concept because it does the subtraction for you, and because it doesn't use global state.

As part of this PR I instrumented one of the clone tests, just as a test of the API. (We probably wouldn't take that change when the PR is merged.)

I have tested this on Windows and Linux, but I could use some help with the Apple version, since I don't have a Mac. I have written what I think is a working implementation of a Mac OS X stopwatch, but I have no idea if it actually works.