Math.max vs compare (v6)

Revision 6 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++) {
	sum += 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.