Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap vs reduce complicated, for loop
(version: 7)
Comparing performance of:
reduce with concat vs flatMap vs for loop
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var arr = Array(1000).fill({data: Array(20).fill({ id: 21353, client_id: 29187, chain_id: 3, restaurant_id: 18, table_id: null, status: 'confirmed', total: 40.5, tax: 4.5, tips: null, created_at: '2023-06-14T10:58:17.000000Z', pay_amount: 40.5, table_code: '12', is_takeaway: false, takeaway_at: null, comment: null, tip_percent: null, cutlery_count: null, tax_percent: null, type: 'dinein', service_charge_percent: '12.5', service_charge: 4.5, subtotal: 31.5, order_items_tags: '["drink", "food"]', roid: 12289, payment_id: null, uuid: '2e5b8fd4-82c2-4d54-ac1b-e29ad3ef894a', pending_at: '2023-06-14 10:58:21+00', confirmed_at: '2023-06-14 10:59:49+00', ready_at: null, completed_at: null, canceled_at: null, last_items_completed_at: '2023-06-14 11:15:05+00', client_address_id: null, is_paid: true, is_external: false, order_configuration: '{}', refund_amount: 0, refund_status: 'no_refunded', discount: '0', created: '14 Jun 2023 at 11:58', pickupAt: '2023-10-07T09:19:03.774+01:00', table_session_id: 4928, items: [ { id: 48738, dish_id: 16222, dish_configuration: { items: [ { id: 323, name: 'Oat Milk' }, { id: 375, name: 'Ice' } ] }, name: 'Flat White', amount: 2, price: 4, total: 9, status: 'pending', created_at: '2023-06-14T10:58:17.000000Z', updated_at: '2023-06-14T10:58:17.000000Z', order_id: 21353, position: null, pending_at: '2023-06-14 10:58:17+00', cooking_at: null, ready_at: null, completed_at: null, canceled_at: null, is_paid: false, modifiers: [ { id: 323, category_id: 71, name: 'Oat Milk', price: 0.5, min_amount: null, max_amount: null, position: 1, created_at: '2021-04-29T14:25:00.000000Z', updated_at: '2022-07-08T17:22:39.000000Z', archived_at: null }, { id: 375, category_id: 89, name: 'Ice', price: 0, min_amount: null, max_amount: null, position: 0, created_at: '2021-05-29T14:01:54.000000Z', updated_at: '2022-05-01T10:29:41.000000Z', archived_at: null } ] }, { id: 48739, dish_id: 16189, dish_configuration: { items: [] }, name: 'Matcha Pancakes Sweet', amount: 2, price: 13.5, total: 27, status: 'completed', created_at: '2023-06-14T10:58:17.000000Z', updated_at: '2023-06-14T11:15:05.000000Z', order_id: 21353, position: null, pending_at: '2023-06-14 10:58:17+00', cooking_at: null, ready_at: '2023-06-14 11:15:04+00', completed_at: '2023-06-14 11:15:05+00', canceled_at: null, is_paid: false, modifiers: [] } ], payment_status: 'paid', payment_type: 'cheqit', left_to_pay: 0, restaurant: { id: 18, name: 'All Day Menu', photo: null, point: { type: 'Point', coordinates: [-0.12411, 51.510926] }, address: '24 Henrietta Street, London, UK', comment: null, description: null, rating: null, price: null, welcome_header: null, welcome_text: null, promo_header: null, chain_id: 3, pos_type: null, taxation: null, choose_table_by_code: false, has_delivery: true, has_takeaway: true, has_dine_in: true, phone: null, opens_at: '7:00 AM', closes_at: '9:00 PM', time_zone_name: 'Europe/London', service_charge_percent: '12.5', default_integration_id: 11, service_charge_round: null, tips_allowed: true, order_notes_allowed: true, cutlery_allowed: false, pat_ordering_enabled: true, pat_menu_enabled: true, is_open: true, times: [ { id: 20, restaurant_id: 18, status: 'enabled', day: 'saturday', from: '07:00:00', to: '21:00:00' }, { id: 18, restaurant_id: 18, status: 'enabled', day: 'thursday', from: '09:00:00', to: '16:00:00' }, { id: 21, restaurant_id: 18, status: 'enabled', day: 'sunday', from: '09:00:00', to: '19:00:00' }, { id: 16, restaurant_id: 18, status: 'enabled', day: 'tuesday', from: '00:00:00', to: '23:45:00' }, { id: 15, restaurant_id: 18, status: 'enabled', day: 'monday', from: '00:00:00', to: '23:45:00' }, { id: 19, restaurant_id: 18, status: 'enabled', day: 'friday', from: '00:00:00', to: '23:45:00' }, { id: 17, restaurant_id: 18, status: 'enabled', day: 'wednesday', from: '00:00:00', to: '23:45:00' } ], integration: { id: 11, restaurant_id: 18, integration_id: 2, token: 'bf3bf188d1117299c125c8b6b8319ed273b992563eab5ed14b85bc4840d52281', params: { server: 'https://api-ru.iiko.services/', api_login: '3e14432b-0c1', organization_id: '60dc121e-1ee7-48cd-b9c3-0a70a1a1784f', terminal_group_id: 'ba61d9d6-f0fb-2628-0180-419a474f0064', payment_id: '81175e04-87fd-43ec-81da-981dddaf6edf', external_menu_id: '9052' }, allowed_webhooks: null, integration: { id: 2, name: 'iiko_transport', title: 'iikoTransport', type: 'pos' } } }, client: { id: 29187, email: '3db93239-5e75-40dd-9e48-9dec871e41a6@cheqit.app', name: 'Client #29187', photo: null, phone: null, chain_id: 3, birthdate: null, status: 'pending' }, table: null })})
Tests:
reduce with concat
arr.reduce((acc, page) => [...acc, ...page.data], [])
flatMap
arr.flatMap((page) => page.data)
for loop
const newArr = []; for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr[i].data.length; j++) { newArr.push(arr[i].data[j]); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
reduce with concat
flatMap
for 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):
I'll do my best to help. It seems like you have a JSON response from an API, and it's not clear what the question is asking for. Can you please provide more context or clarify what you'd like me to assist with? For example, are you looking for: 1. Help parsing or understanding the JSON response? 2. Assistance with performing calculations or operations on the data in the response? 3. Something else entirely? Additionally, it looks like there are three sections at the top of your message: "JSON Response", "Individual test cases", and "Latest benchmark result". Can you please clarify what these sections relate to?
Related benchmarks:
flatMap vs reduce (inner object111)
flatMap vs reduce (inner object1111)
flatMap vs reduce (inner object11111)
Reduce vs flatMap performance
flatMap vs reduce with push testtttteste212312
Comments
Confirm delete:
Do you really want to delete benchmark?