function vs. Math.min vs. if condition (v11)

Revision 11 of this benchmark created by Hendry on


Setup

function getMin(a, b) {
   return (a < b) ? a : b;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
if condition
var num, min = 100;

for (var i = 0; i < 100; i++) {
 num = (Math.random() * 100) >> 0;
 if (num < min) {
  min = num;
 }
}
ready
Math.min
var min = Math.min(100, (Math.random() * 100) >> 0);
ready
function
var min = getMin(100, (Math.random() * 100) >> 0);
ready

Revisions

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