<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var directAddresses = [];
for(var i=1; i< 100; i++) {
directAddresses.push(`${i}deliverymanage@direct.com`);
}
var mySetDomains = new Set();
for(var i=1; i< 10000; i++) {
mySetDomains.add(`${i}direct.com`);
}
var usingArrayDomains = [];
for(var j=1; j< 10000; j++) {
usingArrayDomains.push(`${j}direct.com`);
}
_.map(directAddresses, (da) => {
const domain = da.split('@')[1];
_.includes(usingArrayDomains, domain);
});
_.map(directAddresses, (da) => {
const domain = da.split('@')[1];
mySetDomains.has(domain);
});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array | |
Set |
Test name | Executions per second |
---|---|
Array | 319.4 Ops/sec |
Set | 20741.7 Ops/sec |
Overview of the Benchmark
The provided JSON represents a JavaScript benchmarking test case on MeasureThat.net. The test measures the performance difference between using an Array and a Set data structure in JavaScript for a specific use case: checking if an element exists in an array.
What is tested?
In this benchmark, two test cases are compared:
usingArrayDomains
) to store domain names and checks if each domain name exists in the array using _.includes(usingArrayDomains, domain)
. This approach requires a linear search through the array for each iteration.mySetDomains
) to store unique domain names and checks if each domain name exists in the set using mySetDomains.has(domain)
. This approach allows for constant-time lookups since Sets use hash tables.Options compared
The two approaches are compared in terms of their performance characteristics:
Pros and Cons
Here are some pros and cons of each approach:
Library and purpose
The lodash
library is used in both test cases. Lodash is a popular JavaScript utility library that provides a set of functional programming helpers, including _.includes()
. The purpose of using Lodash is to simplify the implementation of the benchmark and make it more concise.
Special JS feature or syntax
There are no special JS features or syntax used in this benchmark other than the use of Arrays and Sets.
Other alternatives
If an alternative approach was needed, here are some options:
Keep in mind that these alternatives may add complexity to the implementation and may not offer significant performance benefits for small datasets.
I hope this explanation helps! Let me know if you have any further questions.