Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array includes vs object key lookup, large arrays
(version: 0)
Comparing performance of:
includes vs lookup
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = Array.from({length:500},(v,k)=>k+1) var b = Object.assign({}, ...a.map((x) => ({[x]: true})));
Tests:
includes
return a.includes(9)
lookup
return b[9]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
lookup
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Browser/OS:
Firefox 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
26375146.0 Ops/sec
lookup
1342648960.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand the provided benchmark. **What is being tested?** The benchmark is comparing two approaches: 1. `array.includes()` for checking if an element exists in an array (`"includes"` test case). 2. Direct key lookup on an object using square brackets (`"lookup"` test case). **Options compared:** The benchmark is comparing the performance of these two approaches when searching for a specific value (in this case, the number 9) in large arrays and objects. **Pros and Cons of each approach:** 1. `array.includes()`: This method checks if the specified element exists in the array by iterating through it from start to end. It's relatively simple and straightforward. * Pros: + Easy to implement and understand. + Works well for most use cases. * Cons: + Can be slower for large arrays, especially when searching for a specific element that is not near the beginning of the array. 2. Direct key lookup on an object using square brackets (`"lookup"` test case): This method directly accesses the property on the object using its key (in this case, `[9]`). * Pros: + Can be faster for large objects when searching for a specific property that is close to the beginning of the object. * Cons: + Requires knowledge of object keys and can lead to errors if not used correctly. **Library usage:** There is no explicit library mentioned in the provided benchmark. However, it's worth noting that `Array.from()` and `Object.assign()` are built-in JavaScript methods, which might be optimized under the hood by modern browsers. **Special JS features or syntax:** The benchmark uses the following special feature: * `let` constants (e.g., `var a = Array.from({length:500},(v,k)=>k+1)`): This is a new way to declare variables in JavaScript, introduced in ECMAScript 2015. It allows for constant declarations that are scoped to the block or function. **Other alternatives:** If you were to reimplement this benchmark using different approaches, some alternative options could be: * Using `for...of` loop with `find()` method on arrays. * Using `Object.keys()` and indexing into an object property by its key index. * Implementing a custom hash table or trie data structure for faster lookups. However, without seeing the benchmark code, it's difficult to recommend alternative approaches that would yield similar results.
Related benchmarks:
Array.find vs map to object then lookup.
iterating from a filled object VS iterating from a map
set.has vs. array.includes (large)
Map convert
Comments
Confirm delete:
Do you really want to delete benchmark?