Skip to main content
Version: Next

getMultiRuntimeSync

This method executes a async function several times and calculates its execution time several times and puts it in an array.

Params

getMultiRuntimeSync(inputFunction,options = { ignoreFirstTime: false, runtimeCount: 5 ,moreDetails : false}) ;
  • inputFunction → The async function we want to calculate its execution times
  • ignoreFirstTime → In this method, you can set this key to true and the first execution is not considered.
javascript tips

The execution time of a function in the first time is completely different from the subsequent times, because JavaScript performs optimizations on the execution of that function.

  • runtimeCount → The number of times you want this function to be executed and its time taken
  • moreDetails → Gives more information than execution times

Returns

<Promise> /*{
runtimeCount: 5,
runtimes: [
2003.727125,
2003.1831670000001,
2003.1965,
2003.2178330000002,
2003.48375
]
}*/
  • Promise → Returns the promise that contains the runtimes

Usage

const inpFuncSync1 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
};

const momentMachine = async () => {
const result = await getMultiRuntimeSync(testFunction);
console.log(result);/*{
runtimeCount: 5,
runtimes: [
2003.727125,
2003.1831670000001,
2003.1965,
2003.2178330000002,
2003.48375
]
}*/
};

momentMachine();

const momentMachine2 = async () => {
const result = await getMultiRuntimeSync(testFunction,{moreDetails : true});
console.log(result);/*{
runtimeCount: 5,
fastestRuntimes: 2003.1831670000001,
slowestRuntimes: 2003.727125,
runtimes: [
2003.727125,
2003.1831670000001,
2003.1965,
2003.2178330000002,
2003.48375
]
}*/
};

momentMachine2();