diff options
| author | Eric Holk <eholk@mozilla.com> | 2011-06-28 17:58:44 -0700 |
|---|---|---|
| committer | Eric Holk <eholk@mozilla.com> | 2011-06-30 11:32:10 -0700 |
| commit | b4a145e60f4bbc90dc780239cc49c024b9f52ca8 (patch) | |
| tree | 020734b92aa7fea2269b3915d45d1d9730c4192c /src/rt/sync/timer.cpp | |
| parent | 441c7e06109772f7ff942682fb6d0a7535f03666 (diff) | |
| download | rust-b4a145e60f4bbc90dc780239cc49c024b9f52ca8.tar.gz rust-b4a145e60f4bbc90dc780239cc49c024b9f52ca8.zip | |
Added a nanosecond timer to time.rs, support for some floating point casts, and a commandline-driven mode for pfib.rs
Diffstat (limited to 'src/rt/sync/timer.cpp')
| -rw-r--r-- | src/rt/sync/timer.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/rt/sync/timer.cpp b/src/rt/sync/timer.cpp index e6fe3688893..3af441c3950 100644 --- a/src/rt/sync/timer.cpp +++ b/src/rt/sync/timer.cpp @@ -9,7 +9,7 @@ timer::timer() { #if __WIN32__ uint64_t ticks_per_second; QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second); - _ticks_per_us = ticks_per_second / 1000000; + _ticks_per_ns = ticks_per_second / 1000; #endif reset(0); } @@ -41,7 +41,7 @@ timer::has_timed_out() { } uint64_t -timer::get_time() { +timer::nano_time() { #ifdef __APPLE__ uint64_t time = mach_absolute_time(); mach_timebase_info_data_t info = {0, 0}; @@ -49,18 +49,23 @@ timer::get_time() { mach_timebase_info(&info); } uint64_t time_nano = time * (info.numer / info.denom); - return time_nano / 1000; + return time_nano; #elif __WIN32__ uint64_t ticks; QueryPerformanceCounter((LARGE_INTEGER *)&ticks); - return ticks / _ticks_per_us; + return ticks / _ticks_per_ns; #else timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * 1000000000LL + ts.tv_nsec) / 1000; + return (ts.tv_sec * 1000000000LL + ts.tv_nsec); #endif } +uint64_t +timer::get_time() { + return nano_time() / 1000; +} + timer::~timer() { // Nop. } |
