2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-12-24 01:02:12 +01:00
|
|
|
require('../common');
|
2016-12-31 00:38:06 +01:00
|
|
|
const assert = require('assert');
|
2012-03-05 17:51:58 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const start = process.hrtime();
|
2012-03-05 17:51:58 +01:00
|
|
|
|
|
|
|
// process.hrtime() should return an Array
|
|
|
|
assert(Array.isArray(start));
|
|
|
|
|
|
|
|
// busy-loop for 2 seconds
|
2017-01-08 14:19:00 +01:00
|
|
|
const now = Date.now();
|
2012-03-05 17:51:58 +01:00
|
|
|
while (Date.now() - now < 2000);
|
|
|
|
|
|
|
|
// get a diff reading
|
2017-01-08 14:19:00 +01:00
|
|
|
const diff = process.hrtime(start);
|
2012-03-05 17:51:58 +01:00
|
|
|
|
|
|
|
// should be at least 1 second, at most 2 seconds later
|
|
|
|
// (the while loop will usually exit a few nanoseconds before 2)
|
|
|
|
assert(diff[0] >= 1);
|
|
|
|
assert(diff[0] <= 2);
|