Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array vs Object Search
(version: 0)
Comparing performance of:
Array vs Object
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var list = []; var obj = {}; for (var i = 0; i < 10; i++) { list[i] = `Testing...${i}` obj[`Testing...${i}`] = `Testing...${i}` }
Tests:
Array
for (var i = 0; i < 10; i++) { const a = `Testing...${i}` for (var z = 0; i < 10; i++) { if (a === list[z]) break; } }
Object
for (var i = 0; i < 10; i++) { const a = obj[`Testing...${i}`] }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array
Object
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 break down the provided JSON data and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark definition is a script that sets up two data structures: an array `list` and an object `obj`. The script then populates both data structures with 10 elements each, using string literals. This creates two separate arrays of strings to be used for searching. **Script Preparation Code** ```javascript var list = []; var obj = {}; for (var i = 0; i < 10; i++) { list[i] = `Testing...${i}`; obj[`Testing...${i}`] = `Testing...${i}`; } ``` This script prepares the data structures and populates them with test data. **Html Preparation Code** There is no HTML preparation code provided, which means that the benchmark does not rely on any specific HTML structure or rendering. **Individual Test Cases** The benchmark has two individual test cases: 1. **Array** ```javascript for (var i = 0; i < 10; i++) { const a = `Testing...${i}`; for (var z = 0; i < 10; i++) { if (a === list[z]) break; } } ``` This test case searches for an element in the array `list` using a nested loop. The outer loop iterates over the elements of the array, and the inner loop checks each element to see if it matches the string literal `a`. If a match is found, the loop breaks. 2. **Object** ```javascript for (var i = 0; i < 10; i++) { const a = obj[`Testing...${i}`]; } ``` This test case searches for an element in the object `obj` using property access. The string literal `a` is used to look up a property on the object, which should return the same value as before. **Library Usage** In both test cases, there are no external libraries being used. **Special JS Features/Syntax** There are no special JavaScript features or syntax being used in these test cases. The code relies solely on standard JavaScript syntax and built-in data structures. **Benchmark Results** The latest benchmark results show the performance of each test case on a Chrome 96 browser on a desktop Windows platform: | Test Case | Executions Per Second | | --- | --- | | Array | 1145941.375 | | Object | 597558.8125 | These results indicate that the array search is significantly faster than the object search. **Alternatives** There are several alternatives for benchmarking JavaScript performance, including: * **V8 Benchmark Suite**: A set of benchmarks developed by Google to measure the performance of V8, the JavaScript engine used in Chrome. * **JSPerf**: A JavaScript benchmarking tool that allows users to create and run their own benchmarks. * **Benchmark.js**: A lightweight JavaScript benchmarking library that can be used to measure the performance of individual functions or scripts. Overall, MeasureThat.net provides a useful platform for testing and comparing the performance of different JavaScript approaches, including array and object searches.
Related benchmarks:
ruse js object vs array
Array constructor vs literal performance, 12345
Javascript Object vs Array.indexOf
array[array.length - 1] vs array.at(-1) (V3)
for vs every simple
Comments
Confirm delete:
Do you really want to delete benchmark?