JSFiddle - React, Tailwind, and code Playground

by dream apple

JavaScript

const method = (a, b) => Math.max(a, b);
const triple = (a, b) => a > b ? a : b;
const bitwise = (a, b) => a ^ ( ( a ^ b) & -(a < b) );
const list = Array.apply(null, new Array(100000)).map((_, i) => i);
const repeat = (f, name, times) => {
  console.time(name);
  while (times -- > 0) {
    list.reduce(f, -1);
  }
  console.timeEnd(name);
}

repeat(method, 'method', 100);
repeat(triple, 'triple', 100);
repeat(bitwise, 'bitwise', 100);