Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure code execution time in VBScript or JavaScript?

What is a good way to measure code execution time in VBScript?

Or failing that how to do it in JavaScript?

like image 634
Rob Segal Avatar asked Dec 31 '09 15:12

Rob Segal


2 Answers

For VBScript you can use Timer:

StartTime = Timer()
EndTime = Timer()
Response.Write("Seconds to 2 decimal places: " & FormatNumber(EndTime - StartTime, 2))

Or ASP Profiler (that is for an ASP environment.)

For JavaScript you can use Date:

var start = new Date().getTime()
alert("Milliseconds: " + (new Date().getTime() - start))

Firebug also has a profiler for JavaScript.

like image 92
jspcal Avatar answered Sep 29 '22 06:09

jspcal


For JavaScript, I would recommend you to use a profiler, like the one built-in in Firebug:

alt text
(source: getfirebug.com)

Other alternatives can be the one included with Google Chrome, or IE8

If you want to do it programmatically, you could use Date objects to get a time difference:

var startTime = new Date();
// ...
// ...
var endTime = new Date();
var delta = endTime - startTime; // difference in milliseconds
like image 20
Christian C. Salvadó Avatar answered Sep 29 '22 06:09

Christian C. Salvadó