Created
October 4, 2018 07:48
-
-
Save walterra/5e249719c15b5a83f70e0d60557a198c to your computer and use it in GitHub Desktop.
JavaScript Benchmarking Utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const benchmarker = { | |
benchmarks: [], | |
getAverage() { | |
return this.benchmarks.reduce((p, c) => p + c, 0) / this.benchmarks.length; | |
}, | |
start() { | |
return (+new Date()); | |
}, | |
end(start) { | |
this.benchmarks.push((+new Date()) - start); | |
console.warn(`${benchmarker.last() / 1000}s / ${benchmarker.getAverage() / 1000}s avg / ${benchmarker.benchmarks.length} benchmarks`); | |
}, | |
last() { | |
return this.benchmarks[this.benchmarks.length - 1]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment