Math.max vs compare (v8)

Revision 8 of this 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++) {
	let max = numbers1[i] > numbers2[i] ? numbers1[i] : numbers2[i];
}
ready
if (stored variable)
for(var i=0;i<all;i++) {
	const num1 = numbers1[i];
	const num2 = numbers2[i];
	let max = num1 > num2 ? num1 : num2;
}
ready

Revisions

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