Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Last active March 29, 2017 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsiii/e6c9bd58b09b053ce2017d7c96b54892 to your computer and use it in GitHub Desktop.
Save jfsiii/e6c9bd58b09b053ce2017d7c96b54892 to your computer and use it in GitHub Desktop.
<!doctype html>
<body>
<script src="https://unpkg.com/lodash/lodash.min.js"></script>
<script src="https://unpkg.com/platform/platform.js"></script>
<script src="https://unpkg.com/benchmark/benchmark.js"></script>
<pre id="output"></pre>
<script>
function log(message) {
document.getElementById("output").innerHTML += message + '\n';
}
</script>
<script>
function runBenchmarks() {
// Example from https://benchmarkjs.com/
var suite = new Benchmark.Suite;
// add tests
log('Starting tests')
suite
.add('RegExp#test', function() {
/o/.test('Hello World!');
})
.add('String#indexOf', function() {
'Hello World!'.indexOf('o') > -1;
})
.add('String#match', function() {
!!'Hello World!'.match(/o/);
})
// add listeners
.on('cycle', function(event) {
log(String(event.target))
})
.on('complete', function() {
log('Tests complete')
log('Fastest is ' + this.filter('fastest').map('name'))
})
// run async
.run({ 'async': true });
}
runBenchmarks()
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment