Skip to content

Instantly share code, notes, and snippets.

@noahehall
Forked from mucaho/generic-js-benchmark.html
Created January 16, 2017 01:56
Show Gist options
  • Save noahehall/a2d3d3eaf5c28b0f6d82322e8edb48b5 to your computer and use it in GitHub Desktop.
Save noahehall/a2d3d3eaf5c28b0f6d82322e8edb48b5 to your computer and use it in GitHub Desktop.
Generic template for benchmarking / performance testing JavaScript code using the [Benchmark node module](https://www.npmjs.com/package/benchmark)
<html>
<head>
<script src="https://wzrd.in/bundle/lodash@4.11"></script>
<script src="https://wzrd.in/bundle/platform@1.3"></script>
<script src="https://wzrd.in/bundle/benchmark@2.1"></script>
</head>
<body>
<script>
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
// add tests
suite.add('FirstTest', function() {
// first test here
})
.add('SecondTest', function() {
// second test here
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run tests async
.run({ 'async': true });
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment