Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
sort-filter vs reduce
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 126
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
sort-filter
1082876.4 Ops/sec
reduce
1509624.5 Ops/sec
Script Preparation code:
// filterFoo = (x) => x.action === "BID" && x.symbol.toLocaleLowerCase().includes('btc') sortFoo = (a, b) => { return a.price - b.price } reduceFoo = (value, item) => { if ( !( item.action === "BID" && item.symbol.toLocaleLowerCase().includes('btc') ) ) return value; return value >= item?.price ? value : item?.price; } // arr = [{ price: 1000000000, action: "ASK", symbol: "BTC_IRT" }, { price: 1000000, action: "ASK", symbol: "BTC_IRT" }, { price: 111111, action: "BID", symbol: "BTC_IRT" }, { price: 100000, action: "BID", symbol: "BTC_IRT" }, { price: 11111, action: "BID", symbol: "BTC_IRT" }, { price: 10000, action: "BID", symbol: "BTC_IRT" }, { price: 1111, action: "BID", symbol: "BTC_IRT" }, { price: 1000, action: "BID", symbol: "BTC_IRT" }, { price: 100, action: "BID", symbol: "BTC_IRT" }, { price: 1, action: "BID", symbol: "BTC_IRT" }, { price: 11111, action: "ASK", symbol: "BTC_USDT" }, { price: 25000, action: "ASK", symbol: "USDT_IRT" }, { price: 11111, action: "ASK", symbol: "USDT_IRT" }, { price: 10000, action: "ASK", symbol: "USDT_IRT" }, { price: 1111, action: "BID", symbol: "USDT_IRT" }]
Tests:
sort-filter
const sorted = arr.filter(filterFoo).sort(sortFoo) const bigPrice = sorted[0].price
reduce
const bigPrice = arr.reduce(reduceFoo, 0)