I need to get time in milliseconds. Please advise.
+6
A:
Use Firebug, enable both Console and Javascript. Click Profile. Reload. Click Profile again. View the report.
Stefan Mai
2008-11-24 11:14:43
Good advice but obviously works only for FF. We often want to compare browser speeds... :-)
PhiLho
2008-11-24 11:27:38
+13
A:
use Date().getTime()
The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
ex.
var start = new Date().getTime();
for (i = 0; i < 50000; ++i) {
// do something
}
var end = new Date().getTime();
var time = end - start;
alert('Execution time: ' + time);
alternatively, getMilliseconds() will give the milliseconds of the current Date object.
Owen
2008-11-24 11:15:23
Note that you can substitute +new Date() for the getTime() call:var start = +new Date();// do stuffalert("Execution time: "+(+new Date())-start);
J c
2008-11-24 13:00:47
+4
A:
You can use console.time: (only with firebug+firefox)
console.time('someFunction timer');
function someFunction(){ ... }
console.timeEnd('someFunction timer')
vsync
2009-12-29 15:05:42