Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
reduce vs filter vs for vs forin vs ternary
(version: 0)
Comparing performance of:
reduce vs filter vs for vs forin vs ternary
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var values = Array(1000).fill(['dupa', 'dupa2']).flat()
Tests:
reduce
values.reduce((prev, status) => prev + +(status === 'dupa'), 0)
filter
values.filter(status => status === 'dupa').length
for
var c = 0; for(var i = 0; i < values.length; ++i) { c += +(values[i] === 'dupa'); }
forin
var c = 0; for(var v in values) { c += +(v === 'dupa'); }
ternary
var c = 0; for(var i = 0; i < values.length; ++i) { c += values[i] === 'dupa' ? 1 : 0; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
reduce
filter
for
forin
ternary
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:
reduce vs filter
reduce vs filter vs for vs forin vs ternary small
flatMap vs reduce on array dict3
Flatmap vs reduce with objects
Comments
Confirm delete:
Do you really want to delete benchmark?