Benchmarks.js
HTML
<script src="https://cdn.rawgit.com/lodash/lodash/4.11.1/dist/lodash.js"></script>
<script src="https://cdn.rawgit.com/bestiejs/benchmark.js/2.1.0/benchmark.js"></script>
JavaScript
var suite = new Benchmark.Suite;
var BOOL_ATTRS_REGEXP = /^(?:disabled|checked|readonly|required|allowfullscreen|auto(?:focus|play)|compact|controls|default|formnovalidate|hidden|ismap|itemscope|loop|multiple|muted|no(?:resize|shade|validate|wrap)?|open|reversed|seamless|selected|sortable|truespeed|typemustmatch)$/
var BOOL_ATTRS_ARRAY = 'disabled|checked|readonly|required|allowfullscreen|autofocus|focus|play|compact|controls|default|formnovalidate|hidden|ismap|itemscope|loop|multiple|muted|noresize|resize|shade|validate|wrap|open|reversed|seamless|selected|sortable|truespeed|typemustmatch'.split('|')
suite.add('RegExp#test', function() {
if (!BOOL_ATTRS_REGEXP.test('checked')) throw 'it must be true!' // second
if (!BOOL_ATTRS_REGEXP.test('truespeed')) throw 'it must be true!' // second last
if (BOOL_ATTRS_REGEXP.test('foo')) throw 'it must be false!' // missing
})
.add('String#indexOf', function() {
if (!~BOOL_ATTRS_ARRAY.indexOf('checked')) throw 'it must be true!' // second
if (!~BOOL_ATTRS_ARRAY.indexOf('truespeed')) throw 'it must be true!' // second last
if (~BOOL_ATTRS_ARRAY.indexOf('foo')) throw 'it must be false!' // missing
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });