Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Created May 18, 2016 15:50
Show Gist options
  • Save jdanyow/ad02981da949a2b5a9198d891a63d1d1 to your computer and use it in GitHub Desktop.
Save jdanyow/ad02981da949a2b5a9198d891a63d1d1 to your computer and use it in GitHub Desktop.
poor man's jsperf
function log(message) {
document.getElementById('status').textContent += message + '\n';
}
log('running...');
var suite = new Benchmark.Suite;
// add 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('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
</head>
<body>
<pre><code id="status"></code></pre>
<script src="https://cdn.jsdelivr.net/g/[email protected],[email protected],[email protected]"></script>
<script src="bench.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment