Compare Math.max() and Tertiary

Benchmark created by amayer42 on


Setup

var list = [1, 2, 3, 4, 5];
  var id1 = 1;
  var id2 = 6;

Test runner

Ready to run.

Testing in
TestOps/sec
Math.max()
var index1 = Math.max(list.indexOf(id1), 0);

var index2 = Math.max(list.indexOf(id2), 0);
ready
Tertiary
var index1 = list.indexOf(id1);
index1 = index1 === -1 ? 0 : index1;

var index2 = list.indexOf(id2);
index2 = index2 === -1 ? 0 : index2;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by amayer42 on