Math.max vs compare

Benchmark created on


Setup

let numbers1 = [];
let numbers2 = [];
for(var i=0;i<2000000;i++) {
	numbers1.push((Math.random())|0)
	numbers2.push((Math.random())|0)
}
let all = numbers1.length;

Test runner

Ready to run.

Testing in
TestOps/sec
math max
for(var i=0;i<all;i++) {
	let max = Math.max(numbers1[i],numbers2[i]);
}
ready
if
for(var i=0;i<all;i++) {
	max = numbers1[i] > numbers2[i] ? numbers1[i] : numbers2[i];
}
ready

Revisions

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