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.

22 lines
610 B
JavaScript

"use strict";
// FIXME: Make separate package, measure-function-call or so
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)
};
};