function vs. Math.min vs. if condition

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
function
function getMin(a, b) {
 return (a < b) ? a : b;
}

var min = 100;

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

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

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

Revisions

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