I'm trying to make a function that will time other JavaScript functions.
Basically, it would do something like this:
var start = new Date().getTime();
// the function
var end = new Date().getTime();
return end - start;
But, I'd like to be able to call it on any function. For example, I could say timeThisFunction(add) or timeThisFunction(subtract) and it would see how long it took the functions add and subtract to run.
Is this possible in JavaScript? I know there's scoping issues that could be involved. What's the best way to implement it?
performance.now()instead ofDate(). It is much more precise.