Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
In vs multiple equality
(version: 0)
Comparing performance of:
Eql vs Arr vs Obj vs Map vs Set
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const tst = "tst_str"; let last_res; const arr = ["str", "str2", "str3", "str4"]; const obj = {"str": true, "str2": true, "str3": true, "str4": true}; const mp = new Map([["str", true], ["str2", true], ["str3", true], ["str4", true]]); const st = new Set(["str", "str2", "str3", "str4"]);
Tests:
Eql
const tst = "tst_str"; let last_res; for (let i = 0; i < 1000; i++) { last_res = tst === "str" last_res = tst === "str2" last_res = tst === "str3" last_res = tst === "str4" }
Arr
const tst = "tst_str"; const arr = ["str", "str2", "str3", "str4"]; let last_res; for (let i = 0; i < 1000; i++) { last_res = arr.includes(tst); }
Obj
const tst = "tst_str"; const obj = {"str": true, "str2": true, "str3": true, "str4": true}; let last_res; for (let i = 0; i < 1000; i++) { last_res = tst in obj; }
Map
const tst = "tst_str"; const mp = new Map([["str", true], ["str2", true], ["str3", true], ["str4", true]]); let last_res; for (let i = 0; i < 1000; i++) { last_res = mp.has(tst); }
Set
const tst = "tst_str"; const st = new Set(["str", "str2", "str3", "str4"]); let last_res; for (let i = 0; i < 1000; i++) { last_res = st.has(tst); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Eql
Arr
Obj
Map
Set
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 benchmark and explain what's being tested, compared options, pros and cons of each approach, and other considerations. **Benchmark Overview** The benchmark is designed to compare the performance of three equality checks: 1. **Simple equality using `===`**: Directly comparing two values using the triple equals operator. 2. **Using an array (`includes()` method)**: Searching for a value in an array using the `includes()` method. 3. **Using an object property access (`in` operator)**: Accessing a property of an object using the `in` operator. **Test Cases** There are four test cases: 1. **Eql (Equality Check)**: Directly comparing two values using `===`. 2. **Arr (Array Search)**: Searching for a value in an array using `includes()`. 3. **Obj (Object Property Access)**: Accessing a property of an object using the `in` operator. 4. **Map (Map Search)**: Searching for a key in a Map object using the `has()` method. 5. **Set (Set Membership)**: Checking if a value is present in a Set object using the `has()` method. **Comparison Options** The benchmark compares the performance of each test case on different browsers, devices, and operating systems. **Pros and Cons of Each Approach** 1. **Simple Equality (`===`)**: * Pros: Simple, efficient, and widely supported. * Cons: Can be slower for large datasets or complex comparisons. 2. **Array Search (`includes()` method)**: * Pros: Efficient for searching in arrays, but can be slower for small datasets. * Cons: May not perform well on older browsers or devices with limited memory. 3. **Object Property Access (`in` operator)**: * Pros: Fast and efficient for accessing properties of objects, even on large datasets. * Cons: May not work correctly on all data types (e.g., non-objects). **Other Considerations** * The benchmark uses a fixed dataset and number of iterations to ensure consistent results across browsers and devices. * The `includes()` method is used with an array of strings, which may affect performance compared to direct equality checks. **Library and Features Used** The benchmark uses the following libraries: * None explicitly mentioned in the JSON data. However, JavaScript's built-in functions are used for each comparison (e.g., `===`, `includes()`, `in` operator). **Special JS Features or Syntax** None mentioned in this specific benchmark. In conclusion, this benchmark compares the performance of three different equality check approaches on various browsers and devices. The results can help developers understand which approach is most efficient for their specific use cases.
Related benchmarks:
map vs fromentries 2
merge maps
js array copy speed comparison...
for of vs map with merge
Map values to Array: Array.from vs Array Spread
Comments
Confirm delete:
Do you really want to delete benchmark?