Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Repetitive calls vs Map
(version: 0)
Comparing performance of:
Repetitive vs Map
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.createReceivedListData = ( id, receivedAt, checklistName, vehicle, driverName, ) => { return { id, receivedAt, checklistName, vehicle, driverName }; }; window.createReceivedListDataCorrect = (dataMatrix) => dataMatrix.map(line => { const [id, receivedAt, checklistName, vehicle, driverName] = line; return { id, receivedAt, checklistName, vehicle, driverName }; })
Tests:
Repetitive
const receivedListRows = [ createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6951', 1613524796305, 'Vistoria', 'HTB-3585 - Audi', 'João Silva' ), createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6952', 1336612366305, 'Checkout', 'GBT-3570 - Mercedes-Benz', 'Adriana Amanda' ), createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6953', 1223886653305, 'Armazenamento', 'PLA-1234 - Ford Focus', 'Kaique Enzo' ), createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6954', 1355967564305, 'Carregamento', 'NES-3025 - Lotus', 'Felipe Benjamin' ), createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6955', 1510728993305, 'Corrida', 'MXM-2683 - Nissan', 'Daniel Benício' ), createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6956', 1749963088305, 'Manutenção', 'NEO-9860 - Bugre', 'Raimundo Diego' ), createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6957', 1053001501305, 'Conserto', 'MZC-7819 - Citroen', 'Jorge Anthony' ), createReceivedListData( 'b3510752-6aa4-4a3e-9333-14630e5b6958', 1039177178305, 'Trabalho', 'PLA-1234 - Ford Focus', 'Marina Amanda' ), ];
Map
const receivedListRowsCorrectData = [ [ 'b3510752-6aa4-4a3e-9333-14630e5b6951', 1613524796305, 'Vistoria', 'HTB-3585 - Audi', 'João Silva' ], [ 'b3510752-6aa4-4a3e-9333-14630e5b6952', 1336612366305, 'Checkout', 'GBT-3570 - Mercedes-Benz', 'Adriana Amanda' ], [ 'b3510752-6aa4-4a3e-9333-14630e5b6953', 1223886653305, 'Armazenamento', 'PLA-1234 - Ford Focus', 'Kaique Enzo' ], [ 'b3510752-6aa4-4a3e-9333-14630e5b6954', 1355967564305, 'Carregamento', 'NES-3025 - Lotus', 'Felipe Benjamin' ], [ 'b3510752-6aa4-4a3e-9333-14630e5b6955', 1510728993305, 'Corrida', 'MXM-2683 - Nissan', 'Daniel Benício' ], [ 'b3510752-6aa4-4a3e-9333-14630e5b6956', 1749963088305, 'Manutenção', 'NEO-9860 - Bugre', 'Raimundo Diego' ], [ 'b3510752-6aa4-4a3e-9333-14630e5b6957', 1053001501305, 'Conserto', 'MZC-7819 - Citroen', 'Jorge Anthony' ], [ 'b3510752-6aa4-4a3e-9333-14630e5b6958', 1039177178305, 'Trabalho', 'PLA-1234 - Ford Focus', 'Marina Amanda' ], ]; createReceivedListDataCorrect(receivedListRowsCorrectData)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Repetitive
Map
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):
**Benchmark Overview** The provided benchmark measures the performance of two approaches: `Repetitive` and `Map`. Both tests create an array of objects using the `createReceivedListData` function, but with different coding styles. **Options Compared** There are two options compared: 1. **Repetitive**: This approach uses a loop to create each object individually. 2. **Map**: This approach uses the `Array.prototype.map()` method to create each object in a single iteration. **Pros and Cons of Each Approach** **Repetitive (Loop)** Pros: * Easy to understand and implement for beginners * Can be optimized with early returns or caching Cons: * Requires multiple iterations, which can lead to slower performance * May result in more memory allocation and garbage collection **Map (Array.prototype.map())** Pros: * More concise and expressive code * Utilizes the optimized `map()` method, which is likely to be faster Cons: * May require a higher-level understanding of JavaScript and its optimization techniques * Can lead to slower performance if not properly optimized (e.g., due to unnecessary function calls) **Library: createReceivedListData** The `createReceivedListData` function takes five arguments (`id`, `receivedAt`, `type`, `name`, and `description`) and returns an object with the specified properties. This function is likely a custom implementation, and its performance impact on the benchmark results. **Device and Browser Impact** The latest benchmark result shows that Chrome 88 on Mac OS X 11.1.0 performs better for both tests, suggesting that device and browser factors contribute to the observed performance differences. In summary, this benchmark highlights the trade-offs between readability and performance in JavaScript programming. While the `Repetitive` approach is more straightforward, the `Map` approach offers a concise and expressive solution that might be faster with proper optimization.
Related benchmarks:
map vs forEach/push
map vs forEach/push (10 000 000 elements)
map vs forEach/push (10 000 000 elements) fixed!
map vs forEach/push (1000 elements) fixed !
map vs forEach/push (10 000 elements)
Comments
Confirm delete:
Do you really want to delete benchmark?