Browse Source

Use timeStartHelper and timeEndHelper instead of time and toMilliseconds

gh-953
Permutator 8 years ago
parent
commit
b09f083167
No known key found for this signature in database GPG Key ID: 763F7A2F18CAB33E
  1. 26
      src/utils/flushTime.js

26
src/utils/flushTime.js

@ -1,25 +1,25 @@
const DEBUG = false; const DEBUG = false;
const map = new Map; const map = new Map;
let time; let timeStartHelper;
let toMilliseconds; let timeEndHelper;
if ( typeof process === 'undefined' ) { if ( typeof process === 'undefined' ) {
time = function time ( previous ) { timeStartHelper = function timeStartHelper () {
const now = window.performance.now(); return window.performance.now();
return previous ? previous - now : now;
}; };
toMilliseconds = function toMilliseconds ( time ) { timeEndHelper = function timeEndHelper ( previous ) {
return time; return window.performance.now() - previous;
}; };
} else { } else {
time = function time ( previous ) { timeStartHelper = function timeStartHelper () {
return previous === undefined ? process.hrtime() : process.hrtime( previous ); return process.hrtime();
}; };
toMilliseconds = function toMilliseconds ( time ) { timeEndHelper = function timeEndHelper ( previous ) {
return time[0] * 1e3 + time[1] / 1e6; const hrtime = process.hrtime( previous );
return hrtime[0] * 1e3 + hrtime[1] / 1e6;
}; };
} }
@ -29,13 +29,13 @@ export function timeStart ( label ) {
time: 0 time: 0
}); });
} }
map.get( label ).start = time(); map.get( label ).start = timeStartHelper();
} }
export function timeEnd ( label ) { export function timeEnd ( label ) {
if ( map.has( label ) ) { if ( map.has( label ) ) {
const item = map.get( label ); const item = map.get( label );
item.time += toMilliseconds( time( item.start ) ); item.time += timeEndHelper( item.start );
} }
} }

Loading…
Cancel
Save