Math.max vs compare (v2)

Revision 2 of this benchmark created on


Setup

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

Test runner

Ready to run.

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

Revisions

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