Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
alter entity
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
original
2703713.2 Ops/sec
alter
137687.5 Ops/sec
Script Preparation code:
window.data = [ [ "155.040", "0.0" ] ] window.state = { entityById: { "155.050": { "amount": 425.2 }, "155.060": { "amount": 1471.5 }, "155.070": { "amount": 678.5 }, "155.080": { "amount": 637.5 }, "155.090": { "amount": 966.6 }, "155.100": { "amount": 343.2 }, "155.110": { "amount": 1116.7 }, "155.120": { "amount": 557.1 }, "155.130": { "amount": 570.2 }, "155.140": { "amount": 91.2 }, "155.150": { "amount": 1509.4 }, "155.160": { "amount": 763.6 }, "155.170": { "amount": 707.3 }, "155.180": { "amount": 80.8 }, "155.190": { "amount": 78.8 }, "155.200": { "amount": 194.3 }, "155.210": { "amount": 698.2 }, "155.220": { "amount": 799.6 }, "155.230": { "amount": 573.3 }, "155.240": { "amount": 631.5 }, "155.250": { "amount": 1011.7 }, "155.260": { "amount": 165.4 }, "155.270": { "amount": 1299.1 }, "155.280": { "amount": 716 }, "155.290": { "amount": 2051.1 }, "155.300": { "amount": 291 }, "155.310": { "amount": 1434.9 }, "155.320": { "amount": 785.8 }, "155.330": { "amount": 703.9 }, "155.340": { "amount": 253.5 }, "155.350": { "amount": 343.1 }, "155.360": { "amount": 1310.2 }, "155.370": { "amount": 1071.7 }, "155.380": { "amount": 494.3 }, "155.390": { "amount": 239.8 }, "155.400": { "amount": 42.1 }, "155.410": { "amount": 1044.6 }, "155.450": { "amount": 670.5 }, "155.460": { "amount": 355.5 }, "155.500": { "amount": 52.8 }, "155.580": { "amount": 3.3 }, "155.590": { "amount": 350.6 }, "155.600": { "amount": 656 }, "155.620": { "amount": 333.6 }, "155.640": { "amount": 85.2 }, "155.650": { "amount": 499.9 } } }
Tests:
original
function getEntityById(state, data) { const entityById = { ...state.entityById } data.forEach(([price, _amount]) => { const amount = Number(_amount) if (amount === 0) { delete entityById[price] } else { entityById[price] = { amount } } }) const dataMap = data.reduce((acc, d) => { acc[d[0]] = Number(d[1]) return acc }, {}) return entityById } getEntityById(window.state, window.data)
alter
function getEntityById(state, data) { const dataMap = data.reduce((acc, d) => { acc[d[0]] = Number(d[1]) return acc }, {}) const newEntityById = Object.keys(state.entityById).reduce((acc, price) => { const dataAmount = dataMap[price] if (dataAmount === undefined) { acc[price] = state.entityById[price] } else if (dataAmount !== 0) { acc[price] = { amount: dataAmount } // update or add } return acc }, {}) return newEntityById } getEntityById(window.state, window.data)