Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Single loops vs chain
(version: 1)
Comparing performance of:
parseLogsLoop vs parseLogsChain
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const input = '{"date":"2024-11-19T20:36:29.668Z","status":"success","time":"4.56s"} {"date":"2024-11-20T17:05:07.177Z","status":"success","time":"0.00s"} {"date":"2024-11-20T17:14:26.737Z","status":"success","time":"0.00s"} {"date":"2024-11-20T17:16:45.236Z","status":"initiated"} {"date":"2024-11-20T17:16:47.353Z","status":"success","time":"0.00s"} {"date":"2024-11-20T19:26:51.544Z","status":"initiated"} {"date":"2024-11-20T19:26:53.456Z","status":"success","time":"0.00s"} '; export const parseLogsLoop = (input) => { const rawLogs = input.split("\n"); const parsedLogs = []; for (const log of rawLogs) { if (!log) continue; const parsedLog = JSON.parse(log); parsedLogs.unshift(parsedLog); } return parsedLogs; }; const parseLogsChain = (input) => { return input .split("\n") .filter((entry) => entry) .map((entry) => JSON.parse(entry.trim())) .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) }
Tests:
parseLogsLoop
parseLogsLoop(input);
parseLogsChain
parseLogsChain(input);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
parseLogsLoop
parseLogsChain
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!
Comments
Confirm delete:
Do you really want to delete benchmark?