Last active
March 29, 2017 19:39
-
-
Save jfsiii/e6c9bd58b09b053ce2017d7c96b54892 to your computer and use it in GitHub Desktop.
Code from https://benchmarkjs.com/
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> | |
<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