sickill/ascii.io-cli — pull request #34 by tycho (2013-08-28 16:03:44+00:00)
Title: asciiio: utilize high resolution monotonic clock when available

time.time()'s resolution (despite its precision) is documented to be at
1-second granularity, which is terrible for something like screencasting:

http://docs.python.org/2/library/time.html#time.time

If we were using Python 3.x, we could just use time.monotonic() and be done
with it, but we're in a largely Python 2.x world right now. For now, let's use
ctypes to load up and use clock_gettime and gettimeofday.

clock_gettime(CLOCK_MONOTONIC,...) exemplifies all the attributes we care about
for this particular use case: it's monotonically increasing, it's high
precision, and it's high resolution. This makes it ideal for determining
timespans.

gettimeofday() is a good alternative, and more widely implemented (e.g. on BSD
and such). It's both high precision and high resolution, but it is *not*
monotonically increasing. It's subject to things like NTP adjustments, which
causes it to sometimes jump backwards or forwards by arbitrary amounts. It's
not ideal, but the higher resolution is a desirable trait.

Signed-off-by: Steven Noonan