I'd like to be able to get the string returned from console.timeEnd('t')
in my Google Chrome Javascript Console.
In this example below, I'd like one variable which would contain "t: 0.276ms"
> console.time('t'); console.timeEnd('t'); t: 0.276ms < undefined
Is this something doable?
log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console. log(A);
You first call console. time() by providing a string argument, then the code that you want to test, then call console. timeEnd() with the same string argument. You'll then see the time it took to run the code in your browser console.
Definition and UsageThe timeEnd() method ends a timer, and writes the result to the console. The timeEnd() method allows you to time code operations for testing purposes.
In Google Chrome 23.0.1262.2 (Official Build 155904) dev, it looks like it's impossible. The only way I found to be able to calculate time with accuracy is to use window.performance.webkitNow()
Here's a simple example:
var start = window.performance.now(); ... var end = window.performance.now(); var time = end - start;
Read more at http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now
simply you can use
var begin=Date.now(); something here ...; var end= Date.now(); var timeSpent=(end-begin)/1000+"secs";
this is the simplest way and it will work on any browser not in only chrome
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With