Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Testing Looping Array of Objects
(version: 0)
Testing Looping Array of Objects
Comparing performance of:
Loop with For vs Loop with Find
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var myArr = [ { "event": "OneTrustLoaded", "OnetrustActiveGroups": ",C0001,C0002,C0003,C0004,", "gtm.uniqueEventId": 1 }, { "event": "OptanonLoaded", "OptanonActiveGroups": ",C0001,C0002,C0003,C0004,", "gtm.uniqueEventId": 8 }, { "event": "OneTrustGroupsUpdated", "OnetrustActiveGroups": ",C0001,C0002,C0003,C0004,", "gtm.uniqueEventId": 11 }, { "trafficType": "extern", "websiteName": "internetstores - fahrrad.de", "country": "de_DE", "language": "de_DE", "environment": "Development", "pageType": "Product Detail Page", "shopCode": "fde", "loggedIn": "Logged out", "currency": "EUR", "event": "Page Meta", "breadcrumb": "Start > Fahrräder > Rennräder > Straßenrennräder > ", "breakpoint": "L", "categoryPath": "", "abtestSegment": "speedkit", "testSegments": null, "gtm.uniqueEventId": 16 }, { "gtm.start": 1692689222302, "event": "gtm.js", "gtm.uniqueEventId": 19 }, { "event": "OneTrustLoaded", "OnetrustActiveGroups": ",C0001,C0002,C0003,C0004,", "gtm.uniqueEventId": 22 }, { "event": "OptanonLoaded", "OptanonActiveGroups": ",C0001,C0002,C0003,C0004,", "gtm.uniqueEventId": 25 }, { "event": "OneTrustGroupsUpdated", "gtm.uniqueEventId": 28 }, { "event": "gaEvent", "eventCategory": "Products", "productId": "1292983", "productName": "FIXIE Inc. Floater Race weiß", "eventAction": "assembly_loaded", "eventLabel": "Assembly Service", "nonInteraction": "true", "gtm.uniqueEventId": 33 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_drawer_loaded", "eventLabel": null, "nonInteraction": true, "gtm.uniqueEventId": 36 }, { "event": "EECproductDetailView", "ecommerce": { "currencyCode": "EUR", "detail": { "actionField": { "list": "Fahrräder", "action": "detail" }, "products": [ { "name": "FIXIE Inc. Floater Race weiß", "id": "1292983", "masterID": "M904225", "brand": "FIXIE Inc.", "category": "Fahrräder", "dimension42": "Available", "dimension51": 4.4, "dimension66": "3729454", "dimension69": "36897", "dimension72": "Lifestyle / Single Speed", "productPrice": 349.99, "price": "294.11", "dimension62": "30", "dimension49": "499.99", "dimension50": "true", "metric2": 150, "metric4": 499.99, "metric7": 1, "metric8": 0, "dimension40": "174", "dimension43": "weiß", "variant": "51cm (28\")", "dimension53": "51cm (28\")", "nonInteraction": true } ] } }, "gtm.uniqueEventId": 39 }, { "event": "gtm.dom", "gtm.uniqueEventId": 42 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 135 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 150 }, { "0": "js", "1": "2023-08-22T07:27:03.620Z" }, { "0": "config", "1": "G-P089MGNZ6F" }, { "event": "gtm.load", "gtm.uniqueEventId": 173 }, { "event": "gtm.click", "gtm.element": {}, "gtm.elementClasses": "", "gtm.elementId": "", "gtm.elementTarget": "", "gtm.elementUrl": "https://images.internetstores.de/products/1292980/02/11ca51/fixie-inc-floater-race-black-2.jpg?forceSize=true&forceAspectRatio=true&useTrim=true&size=90x90", "gtm.uniqueEventId": 196 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_drawer_loaded", "eventLabel": null, "nonInteraction": true, "gtm.uniqueEventId": 201 }, { "event": "gaEvent", "eventCategory": "Products", "productId": "1292980", "productName": "FIXIE Inc. Floater Race schwarz", "productPrice": 499, "eventAction": "Color Sibling", "eventLabel": "Product Detail Page", "productVariant": "3729439", "addPrice": true, "masterID": "M904225", "productAvailability": "Verfügbar", "gtm.uniqueEventId": 216 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 231 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 246 }, { "event": "gtm.click", "gtm.element": {}, "gtm.elementClasses": "", "gtm.elementId": "", "gtm.elementTarget": "", "gtm.elementUrl": "https://images.internetstores.de/products/1292983/02/beb46e/fixie-inc-floater-race-white-7.jpg?forceSize=true&forceAspectRatio=true&useTrim=true&size=90x90", "gtm.uniqueEventId": 261 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_drawer_loaded", "eventLabel": null, "nonInteraction": true, "gtm.uniqueEventId": 266 }, { "event": "gaEvent", "eventCategory": "Products", "productId": "1292983", "productName": "FIXIE Inc. Floater Race weiß", "productPrice": 349.99, "eventAction": "Color Sibling", "eventLabel": "Product Detail Page", "productVariant": "3729454", "addPrice": true, "masterID": "M904225", "productAvailability": "Verfügbar", "gtm.uniqueEventId": 281 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 296 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 311 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 326 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 341 }, { "event": "gtm.click", "gtm.element": {}, "gtm.elementClasses": "", "gtm.elementId": "", "gtm.elementTarget": "", "gtm.elementUrl": "https://images.internetstores.de/products/1292980/02/11ca51/fixie-inc-floater-race-black-2.jpg?forceSize=true&forceAspectRatio=true&useTrim=true&size=90x90", "gtm.uniqueEventId": 356 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_drawer_loaded", "eventLabel": null, "nonInteraction": true, "gtm.uniqueEventId": 361 }, { "event": "gaEvent", "eventCategory": "Products", "productId": "1292980", "productName": "FIXIE Inc. Floater Race schwarz", "productPrice": 499, "eventAction": "Color Sibling", "eventLabel": "Product Detail Page", "productVariant": "3729439", "addPrice": true, "masterID": "M904225", "productAvailability": "Verfügbar", "gtm.uniqueEventId": 376 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 391 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 406 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 421 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_init_loaded", "nonInteraction": "true", "gtm.uniqueEventId": 436 }, { "event": "gtm.click", "gtm.element": {}, "gtm.elementClasses": "cyc-flex cyc-flex--middle", "gtm.elementId": "", "gtm.elementTarget": "", "gtm.elementUrl": "", "gtm.uniqueEventId": 451 }, { "event": "gaEvent", "eventCategory": "Products", "productId": "1292980", "productName": "FIXIE Inc. Floater Race schwarz", "eventAction": "Geometry table Link", "gtm.uniqueEventId": 456 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_open_framesize_modal", "nonInteraction": false, "gtm.uniqueEventId": 471 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_open_framesize_modal", "nonInteraction": false, "gtm.uniqueEventId": 486 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_heightViewOpened", "eventLabel": null, "nonInteraction": false, "gtm.uniqueEventId": 501 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_heightViewOpened", "eventLabel": null, "nonInteraction": false, "gtm.uniqueEventId": 516 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_resultShown", "eventLabel": "4052406308903_51cm", "nonInteraction": true, "gtm.uniqueEventId": 531 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_resultShown", "eventLabel": "4052406308903_51cm", "nonInteraction": true, "gtm.uniqueEventId": 546 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_recommendationAvailable", "eventLabel": "4052406308903_tooSmall", "nonInteraction": true, "gtm.uniqueEventId": 561 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_recommendationAvailable", "eventLabel": "4052406308903_tooSmall", "nonInteraction": true, "gtm.uniqueEventId": 576 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_close_framesize_modal", "eventLabel": "4052406308903", "nonInteraction": false, "gtm.uniqueEventId": 591 }, { "event": "gaEvent", "eventCategory": "Smartfit", "eventAction": "smartfit_close_framesize_modal", "eventLabel": "4052406308903", "nonInteraction": false, "gtm.uniqueEventId": 606 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 621 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 626 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 631 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 636 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 641 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 646 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 651 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 656 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 661 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 666 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 671 }, { "event": "gtm.pageError", "gtm.errorMessage": "Uncaught TypeError: Cannot read properties of null (reading 'appendChild')", "gtm.errorUrl": "webpack://@internetstores/internetstores_cartridges/./node_modules/tiny-slider/src/tiny-slider.module.js?", "gtm.errorLineNumber": 563, "gtm.uniqueEventId": 676 } ];
Tests:
Loop with For
let eventFound = false; for (let i = 0; i <= myArr.length; i++) { const evt = myArr[i]; if (evt["gtm.uniqueEventId"] === 676) { eventFound = true; break; } }
Loop with Find
let eventFound = myArr.find((evt) => evt["gtm.uniqueEventId"] === 676)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Loop with For
Loop with Find
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):
It looks like we have a JSON response from a performance benchmarking tool, possibly Google PageSpeed Insights or another similar tool. The main content of the response appears to be an array of objects, each representing a test case for a benchmarking scenario. Each object contains the following properties: * `event`: The event name, which in this case is always "gtm.pageError". * `gtm.errorMessage`: An error message indicating that an uncaught TypeError occurred while trying to access the `appendChild` property of null. * `gtm.errorUrl`: A URL associated with the error, specifically a module file for Tiny Slider. * `gtm.errorLineNumber`: The line number in the code where the error occurred (all 563). * `gtm.uniqueEventId`: A unique identifier for the event (671). The array also contains two individual test cases: 1. A "Loop with For" test case, which defines a loop that iterates over an array (`myArr`) and checks if the current element's `uniqueEventId` property matches 676. 2. A "Loop with Find" test case, which defines a loop that uses the `find()` method to iterate over the same array and find an element with a matching `uniqueEventId`. Finally, the response also includes two benchmark results: 1. A result for the "Loop with Find" test case, which reports: * `RawUAString`: The user agent string of the browser (Chrome 115 on Mac OS X). * `Browser`: The browser name and version. * `DevicePlatform`: The device platform (Desktop). * `OperatingSystem`: The operating system (Mac OS X 10.15.7). * `ExecutionsPerSecond`: A value indicating the number of executions per second. * `TestName`: The test case name ("Loop with Find"). 2. A result for the "Loop with For" test case, which reports similar information, but with a different execution rate. Overall, these results suggest that the "Loop with Find" test case is faster than the "Loop with For" test case, indicating that using `find()` to iterate over an array can be more efficient in this specific scenario.
Related benchmarks:
Object.hasOwnProperty vs Object in vs Object[] vs Array.indexOf vs Array.includes v2
_.filter with large objects 2
_.filter with large arrays of objects
Object.hasOwnProperty vs Object in vs Object[] vs Array.indexOf vs Array.includes1231231
Object.hasOwnProperty vs Object in vs Object[] vs Array.indexOf vs Array.includes times 10
Comments
Confirm delete:
Do you really want to delete benchmark?