Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Speed of finding max value
Uses 4 different approaches: loop, Math.max.apply, reduce, and sort
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Loop
39319.7 Ops/sec
Math.max.apply
22121.8 Ops/sec
Reduce
83916.8 Ops/sec
Sort
12199.4 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const toSearch = []; for (let index = 0; index < 5000; index++) { toSearch.push({ x: Math.random(), y: Math.random() }); } toSearch.push({ x: 1, y: 1 });
Tests:
Loop
let max = 0; for (let i = 0; i < toSearch.length; i++) { if (toSearch[i].x > max) { max = toSearch[i].x; } }
Math.max.apply
let max = Math.max.apply(null, toSearch.map(function (o) { return o.x; }));
Reduce
let max = toSearch.reduce((acc, value) => { return (acc = acc > value.x ? acc : value.x); }, 0);
Sort
toSearch.sort((one, two) => two.x - one.x); let max = toSearch[0].x;