static uint64
test_timing(unsigned int duration)
{
- uint64 total_time;
- int64 time_elapsed = 0;
uint64 loop_count = 0;
- uint64 prev,
- cur;
instr_time start_time,
end_time,
- temp;
+ prev,
+ cur;
/*
* Pre-zero the statistics data structures. They're already zero by
largest_diff = 0;
largest_diff_count = 0;
- total_time = duration > 0 ? duration * INT64CONST(1000000000) : 0;
-
INSTR_TIME_SET_CURRENT(start_time);
- cur = INSTR_TIME_GET_NANOSEC(start_time);
+ cur = start_time;
- while (time_elapsed < total_time)
+ end_time = start_time;
+ INSTR_TIME_ADD_NANOSEC(end_time, duration * NS_PER_S);
+
+ while (INSTR_TIME_GT(end_time, cur))
{
int32 diff,
bits;
+ instr_time diff_time;
prev = cur;
- INSTR_TIME_SET_CURRENT(temp);
- cur = INSTR_TIME_GET_NANOSEC(temp);
- diff = cur - prev;
+ INSTR_TIME_SET_CURRENT(cur);
+
+ diff_time = cur;
+ INSTR_TIME_SUBTRACT(diff_time, prev);
+ diff = INSTR_TIME_GET_NANOSEC(diff_time);
/* Did time go backwards? */
if (unlikely(diff < 0))
largest_diff_count++;
loop_count++;
- INSTR_TIME_SUBTRACT(temp, start_time);
- time_elapsed = INSTR_TIME_GET_NANOSEC(temp);
}
+ /* Refresh end time to be the actual time spent (vs the target end time) */
INSTR_TIME_SET_CURRENT(end_time);
INSTR_TIME_SUBTRACT(end_time, start_time);
*
* INSTR_TIME_ADD(x, y) x += y
*
+ * INSTR_TIME_ADD_NANOSEC(t, n) x += y in nanoseconds (converts to ticks)
+ *
* INSTR_TIME_SUBTRACT(x, y) x -= y
*
* INSTR_TIME_ACCUM_DIFF(x, y, z) x += (y - z)
#define INSTR_TIME_GET_NANOSEC(t) \
((int64) (t).ticks)
+#define INSTR_TIME_ADD_NANOSEC(t, n) \
+ ((t).ticks += (n))
+
#else /* WIN32 */
#define INSTR_TIME_GET_NANOSEC(t) \
((int64) ((t).ticks * ((double) NS_PER_S / GetTimerFrequency())))
+#define INSTR_TIME_ADD_NANOSEC(t, n) \
+ ((t).ticks += ((n) / ((double) NS_PER_S / GetTimerFrequency())))
+
#endif /* WIN32 */