Get the milliseconds with Javascript and measure time
Posted May 15th, 2009 in Javascript
If you need to measure how long something takes with Javascript you can use the Date() object to get a start timestamp and then compare it later on using a second Date() object. Although I'm sure there are other benchmarking plugins etc available this can be a quick and easy way to benchmark something in Javascript.
First get the start timestamp as follows. This is the current time in milliseconds.
var start = new Date().getTime();
Then do your processing and substract start from the current time in millseconds.
var elapsed = new Date().getTime() - start;
This will give you the time taken between the two points in time in milliseconds.
Related posts:
- Get the number of days in a month with Javascript (Friday, December 18th 2009)
- Get a UNIX timestamp with Javascript (Tuesday, May 12th 2009)
- Format a date time in Javascript in database format (Friday, April 24th 2009)
- How to get the timezone offset with Javascript (Tuesday, February 17th 2009)
- Using setTimeout() with Javascript (Tuesday, January 27th 2009)

Comments
blog comments powered by Disqus