Created
May 18, 2016 15:50
-
-
Save jdanyow/ad02981da949a2b5a9198d891a63d1d1 to your computer and use it in GitHub Desktop.
poor man's jsperf
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
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 }); |
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
<!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