Switched to monotonic clock. Added some code that might work on Windows but is untested as I don't have a Windows machine.