Skip to main content
Version: 0.4.0

getMultiRuntimeCb

This method executes a async function several times and calculates its execution time several times and puts it in an array and makes it available to you as a callback.

Params

getMultiRuntimeCb(inputFunction,Cb,options = { ignoreFirstTime: false, runtimeCount: 5 }) ;
  • inputFunction → The async function we want to calculate its execution times
  • Cb → A function that will be called as a callback and the output will be passed to this function
take care

When you use this method, be sure to define the callback function

  • 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

Returns

cb(err,runtimes){
//codes
}
  • err → In case of any problem that causes this method to not be able to calculate runtimes, it will return the error in this parameter.
  • runtimes → Runtimes object is placed in this parameter

Usage

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

getMultiRuntimeCb(inpFuncSync1,(err,result)=>{
console.log(result);/*{
runtimeCount: 5,
runtimes: [
2003.727125,
2003.1831670000001,
2003.1965,
2003.2178330000002,
2003.48375
]
}*/
})