The following examples show how to determine the elapsed time between two JavaScript dates in milliseconds.
// To test a function and get back its return function printElapsedTime(fTest) { let nStartTime = Date.now(), vReturn = fTest(),/*from ww w .j a v a2 s .c om*/ nEndTime = Date.now() console.log(`Elapsed time: ${ String(nEndTime - nStartTime) } milliseconds`) return vReturn } function my(){ for (let i = 0; i < 10000; i++) { for (let i = 0; i < 10000; i++) { let doSomething = i * i * i; } } return 123; } let yourFunctionReturn = printElapsedTime(my); console.log(yourFunctionReturn);