Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Max of Mins: Data Blocks
(version: 0)
Comparing performance of:
Lodash Map vs For Loop to Block Array vs Maps
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
//-- must be var to scope globally var data = [2, 5, 4, 6, 3, 7, 8, 4, 6, 1, 6, 2, 8, 8, 7, 6]; var blockLength = 3;
Tests:
Lodash Map
const numBlocks = data.length - blockLength + 1; const minPerBlock = _.range(0, numBlocks).map((i) => Math.min(...data.slice(i, i + blockLength)) ); const maxOfMins = Math.max(...minPerBlock); console.log(minPerBlock); console.log(maxOfMins);
For Loop to Block Array
const numBlocks = data.length - blockLength + 1; const minPerBlock = []; for (let i = 0; i < numBlocks; ++i) { const block = data.slice(i, i + blockLength); minPerBlock.push(Math.min(...block)); } const maxOfMins = Math.max(...minPerBlock); console.log( minPerBlock ) console.log( maxOfMins )
Maps
const minPerBlock = [...data].map((v, idx, self) => { return self.length > idx+(blockLength-1) ? self.slice(idx, idx + blockLength) : [0]; }).map((group)=> Math.min(...group) ); const maxOfMins = Math.max(...minPerBlock); console.log( minPerBlock ) console.log( maxOfMins )
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash Map
For Loop to Block Array
Maps
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
CircleSmallTest
lodash slice
Length vs Lodash Size
Last Lodash Test
native slice vs lodash slice
Comments
Confirm delete:
Do you really want to delete benchmark?