I can easily do this:
console.time('mytimer');
doSomeWork();
console.timeEnd('mytimer');
But is it possible to calculate time in multiple functions. I need to define the script's start time in a global variable. Then inside multiple functions I will write how many miliseconds passed since the start of the time. And write the name of the function Something like this:
console.time('mytimer');
doSomeWork() {
// console.log(difference between now and "mytimer"s start time)
// console.log(name of the function: doSomeWork())
};
doSomeWork2() {
// console.log(difference between now and "mytimer"s start time)
// console.log(name of the function: doSomeWork2())
};
doSomeWork3() {
// console.log(difference between now and "mytimer"s start time)
// console.log(name of the function: doSomeWork3())
};
console.timeEnd('mytimer');
I will use this in Chrome 26+ for debug issues so using browser dependent functions (for example: arguments.callee.name) is not a problem.
Edit: To clearize my problem.
This works:
console.time('myTimer1');
console.timeEnd('myTimer1');
This doesn't work:
console.time('myTimer2');
console.time('myTimer2');
Edit: Of course it is possible to write too much timers and check time of each of them. But I need to know elapsed time since the javascript code is started in each lap.