From ae82c520e6e9a3eddb130ab876b400b6ecb697f6 Mon Sep 17 00:00:00 2001 From: Permutator Date: Sat, 10 Sep 2016 17:38:39 -0700 Subject: [PATCH 1/4] Fixed "process.hrtime() only accepts an Array tuple." error --- src/utils/flushTime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/flushTime.js b/src/utils/flushTime.js index 000fbb9..8261189 100644 --- a/src/utils/flushTime.js +++ b/src/utils/flushTime.js @@ -10,8 +10,8 @@ if ( typeof process === 'undefined' ) { }; } else { time = function time ( previous ) { - const hrtime = process.hrtime( previous ); if ( previous ) { + const hrtime = process.hrtime( previous ); return hrtime[0] * 1e3 + hrtime[1] / 1e6; } }; From 10808f733b5389ddeaa97e3b2ea3215cb7b8037e Mon Sep 17 00:00:00 2001 From: Permutator Date: Sat, 10 Sep 2016 17:59:17 -0700 Subject: [PATCH 2/4] Made flushTime actually work again --- src/utils/flushTime.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils/flushTime.js b/src/utils/flushTime.js index 8261189..c6c95e3 100644 --- a/src/utils/flushTime.js +++ b/src/utils/flushTime.js @@ -1,20 +1,25 @@ const DEBUG = false; const map = new Map; -let time; +let time, toMilliseconds; if ( typeof process === 'undefined' ) { time = function time ( previous ) { const now = window.performance.now(); return previous ? previous - now : now; }; + + toMilliseconds = function toMilliseconds ( time ) { + return time; + } } else { time = function time ( previous ) { - if ( previous ) { - const hrtime = process.hrtime( previous ); - return hrtime[0] * 1e3 + hrtime[1] / 1e6; - } + return previous === undefined ? process.hrtime() : process.hrtime( previous ); }; + + toMilliseconds = function toMilliseconds ( time ) { + return time[0] * 1e3 + time[1] / 1e6; + } } export function timeStart ( label ) { @@ -29,7 +34,7 @@ export function timeStart ( label ) { export function timeEnd ( label ) { if ( map.has( label ) ) { const item = map.get( label ); - item.time += time( item.start ); + item.time += toMilliseconds( time( item.start ) ); } } From d31c75bc70ddf134331411e7278aef55310464b0 Mon Sep 17 00:00:00 2001 From: Permutator Date: Sat, 10 Sep 2016 18:02:32 -0700 Subject: [PATCH 3/4] Pass linting --- src/utils/flushTime.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/flushTime.js b/src/utils/flushTime.js index c6c95e3..c94ac73 100644 --- a/src/utils/flushTime.js +++ b/src/utils/flushTime.js @@ -1,7 +1,8 @@ const DEBUG = false; const map = new Map; -let time, toMilliseconds; +let time; +let toMilliseconds; if ( typeof process === 'undefined' ) { time = function time ( previous ) { @@ -11,7 +12,7 @@ if ( typeof process === 'undefined' ) { toMilliseconds = function toMilliseconds ( time ) { return time; - } + }; } else { time = function time ( previous ) { return previous === undefined ? process.hrtime() : process.hrtime( previous ); @@ -19,7 +20,7 @@ if ( typeof process === 'undefined' ) { toMilliseconds = function toMilliseconds ( time ) { return time[0] * 1e3 + time[1] / 1e6; - } + }; } export function timeStart ( label ) { From b09f0831675f6d4237e83ec6fc16e07afa517cba Mon Sep 17 00:00:00 2001 From: Permutator Date: Sat, 10 Sep 2016 18:17:30 -0700 Subject: [PATCH 4/4] Use timeStartHelper and timeEndHelper instead of time and toMilliseconds --- src/utils/flushTime.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/utils/flushTime.js b/src/utils/flushTime.js index c94ac73..683e28c 100644 --- a/src/utils/flushTime.js +++ b/src/utils/flushTime.js @@ -1,25 +1,25 @@ const DEBUG = false; const map = new Map; -let time; -let toMilliseconds; +let timeStartHelper; +let timeEndHelper; if ( typeof process === 'undefined' ) { - time = function time ( previous ) { - const now = window.performance.now(); - return previous ? previous - now : now; + timeStartHelper = function timeStartHelper () { + return window.performance.now(); }; - toMilliseconds = function toMilliseconds ( time ) { - return time; + timeEndHelper = function timeEndHelper ( previous ) { + return window.performance.now() - previous; }; } else { - time = function time ( previous ) { - return previous === undefined ? process.hrtime() : process.hrtime( previous ); + timeStartHelper = function timeStartHelper () { + return process.hrtime(); }; - toMilliseconds = function toMilliseconds ( time ) { - return time[0] * 1e3 + time[1] / 1e6; + timeEndHelper = function timeEndHelper ( previous ) { + const hrtime = process.hrtime( previous ); + return hrtime[0] * 1e3 + hrtime[1] / 1e6; }; } @@ -29,13 +29,13 @@ export function timeStart ( label ) { time: 0 }); } - map.get( label ).start = time(); + map.get( label ).start = timeStartHelper(); } export function timeEnd ( label ) { if ( map.has( label ) ) { const item = map.get( label ); - item.time += toMilliseconds( time( item.start ) ); + item.time += timeEndHelper( item.start ); } }