-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconsole-time.js
48 lines (37 loc) · 869 Bytes
/
console-time.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
48
;(function( console ) {
'use strict';
var timers;
// do we have access to the console?
if ( !console ) {
return;
}
// table of current timers
timers = {};
/**
* Stores current time in milliseconds
* in the timers map
*
* @param {string} timer name
* @return {void}
*/
console.time = function( name ) {
if ( name ) {
timers[ name ] = Date.now();
}
};
/**
* Finds difference between when this method
* was called and when the respective time method
* was called, then logs out the difference
* and deletes the original record
*
* @param {string} timer name
* @return {void}
*/
console.timeEnd = function( name ) {
if ( timers[ name ] ) {
console.log( name + ': ' + (Date.now() - timers[ name ]) + 'ms' );
delete timers[ name ];
}
};
}( window.console ));