Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs String.includes vs Object Hashmap vs Set vs Array.indexOf (Testing 0...N)
(version: 0)
Matching a string against more than one possibility.
Comparing performance of:
Array.includes vs String.includes vs Object Hash-map vs ES6 Set vs Array.indexOf
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var testArray = Array.from(Array(1000).keys()).map(i => new Date('2020-01-01 00:00:00.' + i).toString()); var testString = testArray.join(','); var objectHash = testArray.reduce((acc, key) => {acc[key] = true; return acc;},{}); var testSet = new Set(testArray);
Tests:
Array.includes
Array.from(Array(1000).keys()).map(i => testArray.includes(new Date('2020-01-01 00:00:00.' + i).toString()));
String.includes
Array.from(Array(1000).keys()).map(i => testString.includes(new Date('2020-01-01 00:00:00.' + i).toString()));
Object Hash-map
Array.from(Array(1000).keys()).map(i => !!objectHash[new Date('2020-01-01 00:00:00.' + i).toString()]);
ES6 Set
Array.from(Array(1000).keys()).map(i => testSet.has(new Date('2020-01-01 00:00:00.' + i).toString()));
Array.indexOf
Array.from(Array(1000).keys()).map(i => testArray.indexOf(new Date('2020-01-01 00:00:00.' + i).toString()) > -1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Array.includes
String.includes
Object Hash-map
ES6 Set
Array.indexOf
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 dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Overview** The provided JSON represents a benchmark that tests the performance of different string matching methods in JavaScript: `Array.includes`, `String.includes`, `Object Hash-map`, `ES6 Set`, and `Array.indexOf`. The test is designed to measure how quickly each method can find a specific value within an array of 1000 strings. **Options Compared** The benchmark compares the following options: 1. **`Array.includes()`**: Uses the `includes()` method on the `testArray`. 2. **`String.includes()`**: Uses the `includes()` method on the `testString`. 3. **`Object Hash-map`**: Uses a hash map data structure to store the test strings and checks if a value exists in the map. 4. **`ES6 Set`**: Uses an ES6 set data structure to store the test strings and checks if a value exists in the set. 5. **`Array.indexOf()`**: Uses the `indexOf()` method on the `testArray`. **Pros and Cons of Each Approach** Here's a brief summary of the pros and cons of each approach: 1. **`Array.includes()`**: Pros: Fast, efficient, and widely supported. Cons: May be slower than other methods for very large arrays. 2. **`String.includes()`**: Pros: Fast and efficient for string matching. Cons: Requires creating a new string object, which can lead to performance issues with very large strings. 3. **`Object Hash-map`**: Pros: Can handle large datasets efficiently. Cons: Requires additional memory allocation and may not be as fast as other methods for small datasets. 4. **`ES6 Set`**: Pros: Efficient and concise way to store unique values. Cons: May not be suitable for all use cases (e.g., searching for a specific value). 5. **`Array.indexOf()`**: Pros: Fast and efficient, but may require additional memory allocation. Cons: Requires iterating through the entire array. **Library and Purpose** The benchmark uses the following libraries: 1. **`Array.from()`**: A modern JavaScript method to create an array from an iterable. 2. **`Set`**: An ES6 data structure for storing unique values. 3. **`Object Hash-map`**: A custom implementation of a hash map, which is not a built-in JavaScript data structure. **Special JS Features or Syntax** The benchmark does not use any special JavaScript features or syntax, such as async/await, Promises, or ES6 classes. **Alternative Implementations** There are several alternative implementations for each method: 1. **`Array.includes()`**: `indexOf()`, `binarySearch()` 2. **`String.includes()`**: `indexOf()`, regular expressions 3. **`Object Hash-map`**: `Map` (built-in JavaScript), custom hash map libraries like `fast-integer-keys` 4. **`ES6 Set`**: Built-in `Set` data structure, alternative implementations like `fast-set` 5. **`Array.indexOf()`**: `indexOf()`, binarySearch() Keep in mind that the performance differences between these alternatives may be small, and the choice of implementation depends on specific use cases and requirements. I hope this explanation helps you understand the benchmarking process on MeasureThat.net!
Related benchmarks:
Array find with indexOf vs includes
equality vs includes
chain of or equals vs includes but smaller
=== vs includes
equals vs includes
Comments
Confirm delete:
Do you really want to delete benchmark?