-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugTimer.js
47 lines (41 loc) · 1.14 KB
/
DebugTimer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* DebugTimer is a great class to test performance by measuring time
*
* DebugTimer.start(className:String)
* DebugTimer.end(className:String)
*
* @author Edwin Veldhuizen <info@edwin.pw>
*/
try{
console.log("")
}catch(e){
console = {log:function(string){}}}
}
var DebugTimer = (function (){
var timers = [],
start = function(functionName){
if(timers[functionName]!=null){
console.log("ERROR :: DebugTimer.start('"+functionName+"') :: Already started or never ended!");
return;
}
var start_time = new Date();
start_time = (start_time.getSeconds()*1000) +start_time.getMilliseconds();
timers[functionName] = start_time;
return this;
},
stop = function(functionName){
var start_time = timers[functionName];
if(start_time==null){
console.log("ERROR :: DebugTimer.stop('"+functionName+"') :: Never started!");
return;
}
var end_time = new Date();
end_time = (end_time.getSeconds()*1000) +end_time.getMilliseconds();
console.log("DebugTimer :: "+functionName+"() took " + (end_time-start_time) +"ms");
timers[functionName] = null;
};
return {
start: start,
stop: stop
}
}());