Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
interleave
(version: 0)
Comparing performance of:
reduce vs while vs for-loop
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function makeid() { return Math.random().toString(32).slice(-7); } function makeArray(length) { return Array.from({length}, makeid) } window.testFixtures = { strings: makeArray(50), chunks: makeArray(49).map(id => () => id) }
Tests:
reduce
const {strings, chunks} = window.testFixtures chunks.reduce(function interleave(text, chunk, i) { return text + chunk() + strings[i + 1] }, strings[0])
while
const {strings, chunks} = window.testFixtures let text = strings[0] const length = chunks.length let i = -1 while(++i < length) { text += (0, chunks[i])() text += strings[i + 1] }
for-loop
const {strings, chunks} = window.testFixtures let text = strings[0] for (let i = 0, length = chunks.length; i < length; i += 1) { text += (0, chunks[i])() text += strings[i + 1] }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
reduce
while
for-loop
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:
Array.prototype.slice vs spread operator -- multiple cases
Array.prototype.slice vs spread operator - objects
Array.prototype.slice vs spread operator - objects 2
Array.prototype.slice vs spread operator - objects 22
Array cloning
Comments
Confirm delete:
Do you really want to delete benchmark?