Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
testing functions
(version: 0)
Comparing performance of:
sina vs mina
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
sina
const responseToTimeseries = (response) => { // your implementation goes here const pointHash = {} class TimeSeriesPoint { constructor(x) { this.x = x this.points = [] this.total = 0 } addPoint(point = 0) { this.points.push(point) this.total += point } } // create {x: point} objects for easy accass const objectified = response.map(({data}) => Object.fromEntries(data)) // get only the list of x's and iterate over them // could get uniques by converting to a set to avoid extra iterations response.flatMap(item => item.data.map(i => i[0])) .forEach(function(key) { // when encountering a new x, add a point to it for each other data set // if it's undefined in a given set, point defaults to 0 if (!pointHash[key]) { pointHash[key] = new TimeSeriesPoint(key) objectified.forEach(function(obj) { pointHash[key].addPoint(obj[key]) }) } }) return pointHash };
mina
const responseToTimeseries = (response) => { return response.reduce((base, { data }, index) => { data.forEach(([key, point]) => { const series = base[key]; if (series) { const { points, total } = series; const pointsDiff = index - points.length; // Add enough 'buffer' 0s to match the current index const buffer = pointsDiff ? new Array(pointsDiff).fill(0, 0, pointsDiff) : []; base[key] = { ...series, points: [...points, ...buffer, point], total: total + point } } else { base[key] = { // Pad as many 0s as needed to match the current index (length) // [0, point] satifies the tests, but data can be crazy sometimes 🤯 // This feels a bit more reliable points: new Array(index).fill(0, 0, index).concat(point), total: point, x: key, } } }) return base; }, {}); };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
sina
mina
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:
Lazy test vs call
Lazy test vs call
Bad await use
Ramda operation vs reduce test 1
Direct call vs bind vs call vs apply vs self (with many params)
Comments
Confirm delete:
Do you really want to delete benchmark?