UNPKG

actionhero

Version:

actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks

34 lines (33 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.eventLoopDelay = void 0; const asyncWaterfall_1 = require("./asyncWaterfall"); /** * Returns the average delay between a tick of the node.js event loop, as measured for N calls of `process.nextTick` */ async function eventLoopDelay(iterations = 10000) { const jobs = []; const sleepyFunc = async () => { return new Promise((resolve) => { const start = process.hrtime(); process.nextTick(() => { const delta = process.hrtime(start); const ms = delta[0] * 1000 + delta[1] / 1000000; resolve(ms); }); }); }; let i = 0; while (i < iterations) { jobs.push(sleepyFunc); i++; } const results = await asyncWaterfall_1.asyncWaterfall(jobs); let sum = 0; results.forEach((t) => { sum += t; }); const avg = Math.round((sum / results.length) * 10000) / 1000; return avg; } exports.eventLoopDelay = eventLoopDelay;