Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
FFfffff
(version: 0)
Comparing performance of:
Reducer vs Multi loop
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var ORDER_STATUSES = { UNKNOWN: 0, DELIVERECT_PARSED: 1, POS_RECEIVED: 2, SENT_TO_DMA: 3, // Order has been sent to the DMA BEFORE_DELIVERECT_PARSE: 4, POS_RECEIPT_NOT_FOUND_YET: 5, RECEIVED_BY_DMA: 6, // Order has been received by the DMA. PRINTED_BY_DMA: 7, // Order has been printed by the DMA. NEW: 10, ACCEPTED: 20, SCHEDULED: 25, REJECTED: 30, DENIED: 35, PRINTED: 40, PREPARING: 50, PREPARED: 60, READY_FOR_PICKUP: 70, COURIER_ARRIVED: 75, IN_DELIVERY: 80, EN_ROUTE_TO_PICKUP: 83, EN_ROUTE_TO_DROPOFF: 87, DELIVERED: 90, DELIVERECT_FINALIZED: 92, AUTO_FINALIZED: 95, CANCEL: 100, CANCELED: 110, DELIVERY_CANCELED: 112, FAILED: 120, FAILED_HANDLED: 129, POS_MOCKED: 130, DELIVERY_FAILED: 131, POS_RECEIVED_FAILED: 121, RETRIABLE_FAILED: 122, MANUAL_RETRY: 123, FAILED_CANCEL: 126 }; var FAILED_STATUSES_THAT_CAN_BE_RESOLVED_INTERNALLY = [ ORDER_STATUSES.FAILED, ORDER_STATUSES.RETRIABLE_FAILED, ORDER_STATUSES.FAILED_HANDLED, ORDER_STATUSES.DELIVERY_CANCELED, ORDER_STATUSES.DELIVERY_FAILED ]; var IN_PROGRESS_ORDERS_STATUSES = [ ORDER_STATUSES.ACCEPTED, ORDER_STATUSES.PRINTED, ORDER_STATUSES.PREPARING ]; var FINISHED_ORDERS_STATUSES = [ ORDER_STATUSES.PREPARED, ORDER_STATUSES.READY_FOR_PICKUP, ORDER_STATUSES.IN_DELIVERY, ORDER_STATUSES.EN_ROUTE_TO_DROPOFF, ORDER_STATUSES.EN_ROUTE_TO_PICKUP, ORDER_STATUSES.COURIER_ARRIVED, ORDER_STATUSES.DELIVERED, ORDER_STATUSES.CANCELED, ORDER_STATUSES.CANCEL, ORDER_STATUSES.POS_MOCKED, ORDER_STATUSES.AUTO_FINALIZED, ORDER_STATUSES.DELIVERECT_FINALIZED, ORDER_STATUSES.DENIED, ORDER_STATUSES.FAILED_CANCEL ]; var SCHEDULED_ORDERS_STATUSES = [ORDER_STATUSES.SCHEDULED]; var NEW_ORDERS_STATUSES = [ ...FAILED_STATUSES_THAT_CAN_BE_RESOLVED_INTERNALLY, ORDER_STATUSES.BEFORE_DELIVERECT_PARSE, ORDER_STATUSES.DELIVERECT_PARSED, ORDER_STATUSES.POS_RECEIVED, ORDER_STATUSES.NEW ]; var ORDER_STATUS_FILTER = { REQUIRES_ATTENTION: "Requires Attention", NEW: "New", IN_PROGRESS: "In Progress", FINISHED: "Finished", SCHEDULED: "Scheduled" }; var DEFAULT_ORDER_STATUS_FILTER_MAP = { [ORDER_STATUS_FILTER.NEW]: NEW_ORDERS_STATUSES, [ORDER_STATUS_FILTER.REQUIRES_ATTENTION]: NEW_ORDERS_STATUSES, [ORDER_STATUS_FILTER.IN_PROGRESS]: IN_PROGRESS_ORDERS_STATUSES, [ORDER_STATUS_FILTER.FINISHED]: FINISHED_ORDERS_STATUSES, [ORDER_STATUS_FILTER.SCHEDULED]: SCHEDULED_ORDERS_STATUSES }; var orderFlowSetting = { value: [20, 40, 50, 60, 70, 80] };
Tests:
Reducer
const firstFinishedStatus = orderFlowSetting.value[orderFlowSetting.value.length - 1]; const [inProgress, finished] = DEFAULT_ORDER_STATUS_FILTER_MAP[ ORDER_STATUS_FILTER.FINISHED ].reduce( ([inProgress, finished], status) => { if (status !== ORDER_STATUSES.DENIED && status < firstFinishedStatus) { inProgress.push(status); } else { finished.push(status); } return [inProgress, finished]; }, [[...DEFAULT_ORDER_STATUS_FILTER_MAP[ORDER_STATUS_FILTER.IN_PROGRESS]], []] ); const result = { ...DEFAULT_ORDER_STATUS_FILTER_MAP, [ORDER_STATUS_FILTER.IN_PROGRESS]: inProgress, [ORDER_STATUS_FILTER.FINISHED]: finished }; console.log(result)
Multi loop
const editedOrderStatusFilterMap = {... DEFAULT_ORDER_STATUS_FILTER_MAP, }; const to_remove = []; DEFAULT_ORDER_STATUS_FILTER_MAP[ORDER_STATUS_FILTER.FINISHED].forEach(orderStatus => { if ( orderStatus !== ORDER_STATUSES.DENIED && orderStatus < orderFlowSetting.value[orderFlowSetting.value.length - 1] ) { editedOrderStatusFilterMap[ORDER_STATUS_FILTER.IN_PROGRESS].push( orderStatus, ); to_remove.push(orderStatus); } }); to_remove.forEach(orderStatus => editedOrderStatusFilterMap[ORDER_STATUS_FILTER.FINISHED].splice( editedOrderStatusFilterMap[ORDER_STATUS_FILTER.FINISHED].indexOf( orderStatus, ), 1, ), ); console.log(editedOrderStatusFilterMap);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Reducer
Multi loop
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!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and analyze the provided benchmark. **Benchmark Definition** The benchmark definition is a JSON object that describes the test case. In this case, there are two individual test cases: "Reducer" and "Multi loop". Both test cases use JavaScript to manipulate an `ORDER_STATUS_FILTER_MAP` object, which maps order statuses to arrays of corresponding order statuses. **Options Compared** In both test cases: * The original `DEFAULT_ORDER_STATUS_FILTER_MAP` object is used. * The same `ORDER_STATUS_FILTER` object is used as a filter for the map keys. * Only specific properties of the `ORDER_STATUS_FILTER_MAP` are modified or iterated over: `[ORDER_STATUS_FILTER.FINISHED]`. However, there's a difference in how these options are manipulated: * In the "Reducer" test case, a new object `firstFinishedStatus` is created using an array index and then used to reduce the original `DEFAULT_ORDER_STATUS_FILTER_MAP`. * In the "Multi loop" test case, another object `editedOrderStatusFilterMap` is created by modifying the original `DEFAULT_ORDER_STATUS_FILTER_MAP`, specifically by removing specific elements from `[ORDER_STATUS_FILTER.FINISHED]`. **Individual Test Cases** Let's analyze each individual test case: ### Reducer The "Reducer" test case uses a reduce method to manipulate the `DEFAULT_ORDER_STATUS_FILTER_MAP`. It creates an array `inProgress` containing statuses that meet certain conditions (i.e., not `ORDER_STATUSES.DENIED` and less than `firstFinishedStatus`) and pushes them into `[ORDER_STATUS_FILTER.IN_PROGRESS]`. The resulting object is then logged. ### Multi loop The "Multi loop" test case iterates over the elements of `[ORDER_STATUS_FILTER.FINISHED]`, checks each element, and removes it from the original map if necessary. This creates a new `editedOrderStatusFilterMap` object with some statuses removed or modified. The resulting object is then logged. **Benchmark Result** The latest benchmark result shows two test cases executed: * "Multi loop" has an average of 26358.705078125 executions per second. * "Reducer" has an average of 24690.796875 executions per second. This indicates that the "Multi loop" test case is slightly faster than the "Reducer" test case, but both are relatively fast. In conclusion, MeasureThat.net provides a comprehensive benchmarking platform for testing JavaScript code performance. By analyzing the provided benchmark definition and individual test cases, we can gain insights into how different code manipulations affect execution speed.
Related benchmarks:
Testing lodash some vs get
test autocomplete computed items
[MH-4355]: lodash / es6 filter perf
[MH-4355][1000]: lodash / es6 filter perf
Join vs loop
Comments
Confirm delete:
Do you really want to delete benchmark?