Benchmark.js Template

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/2.1.1/benchmark.min.js"></script>

JavaScript

var suite = new Benchmark.Suite;
function print(str) {
	const p = document.createElement('p');
  p.textContent = str;
	document.body.appendChild(p);
}

const HD = 1;

const chan0 = { tags: [0] };
const chan1 = { tags: [1] };

function a(ch) {
  return ch.tags.some(tag => tag === HD);
}

const helper = tag => tag === HD;
function b(ch) {
	return ch.tags.some(helper);
}

function c(ch) {
	for (const tag of ch.tags) {
  	if (tag === HD) return true;
  }
  return false;
}

// add tests
suite
.add('a', function() {
  a(chan0)
  a(chan1)
})
.add('b', function() {
	b(chan0)
	b(chan1)
})
.add('c', function() {
	c(chan0)
	c(chan1)
})
.on('cycle', function(event) {
  print(String(event.target));
})
.on('complete', function() {
  print('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });