Math.max vs compare (v10)

Revision 10 of this benchmark created on


Setup

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

Test runner

Ready to run.

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

}
ready

Revisions

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