You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
548 B
JavaScript
20 lines
548 B
JavaScript
3 years ago
|
"use strict";
|
||
|
|
||
|
function hrtimeToNanoseconds(time) {
|
||
|
// If the numbers here become big enough to cause loss of precision, we probably have bigger issues than numeric precision...
|
||
|
return (time[0] * 1e9) + time[1];
|
||
|
}
|
||
|
|
||
|
module.exports = function measureTime(func) {
|
||
|
// let startTime = process.hrtime.bigint();
|
||
|
let startTime = hrtimeToNanoseconds(process.hrtime());
|
||
|
let result = func();
|
||
|
// let endTime = process.hrtime.bigint();
|
||
|
let endTime = hrtimeToNanoseconds(process.hrtime());
|
||
|
|
||
|
return {
|
||
|
value: result,
|
||
|
time: (endTime - startTime)
|
||
|
};
|
||
|
};
|