Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
runtest
(version: 0)
411
Comparing performance of:
inc vs key vs set
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = (new Array(100000)).fill(null).reduce((prev, newVal) => {prev[Math.random() + ''] = Math.random() + ''; return prev; }, { sausage: 'tst' }); var array = Object.keys(obj); var set = new Set(array);
Tests:
inc
array.includes('sausage')
key
obj['sausage']
set
set.has('saudage')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
inc
key
set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Linux; Android 11; PEDM00 Build/RKQ1.201105.002) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 83 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
inc
3631929.0 Ops/sec
key
3416152.0 Ops/sec
set
3313183.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, the different approaches compared, their pros and cons, and other considerations. **Benchmark Definition JSON** The provided benchmark definition defines a JavaScript test case with two parts: 1. **Script Preparation Code**: This section creates an array of 100,000 objects with random keys and values. The `fill()` method is used to initialize the array with null values, and then the `reduce()` method is used to create a new object (`obj`) with random keys and values. 2. **Html Preparation Code**: This section is empty (`null`), indicating that no HTML code is required for the benchmark. **Individual Test Cases** There are three test cases defined: 1. **Test Case 1: "inc"** * **Benchmark Definition:** `array.includes('sausage')` * **Purpose:** This test case checks how fast a browser can search for a specific value (`'sausage'`) in an array. 2. **Test Case 2: "key"** * **Benchmark Definition:** `obj['sausage']` * **Purpose:** This test case checks how fast a browser can access a property of an object using a bracket notation (`obj['sausage']`). 3. **Test Case 3: "set"** * **Benchmark Definition:** `set.has('saudage')` * **Purpose:** This test case checks how fast a browser can check if a specific value exists in a Set data structure. **Library Used** In the provided benchmark definition, a JavaScript built-in object `Set` is used to create a set of unique values (`var set = new Set(array);`). The `Set` data structure provides efficient membership testing operations (e.g., `has()`). **Special JS Feature/Syntax** None of the benchmark definitions use any special JavaScript features or syntax. They are straightforward, vanilla JavaScript code. **Other Considerations** The benchmark definition does not include any user input or dynamic values, which could affect the results of the test cases. The script preparation code creates a fixed array and object with random keys and values, ensuring that the test cases are deterministic. **Alternatives** There are several alternative approaches to creating benchmarks for JavaScript performance testing: 1. **Using existing libraries**: Consider using established benchmarking libraries like `BenchmarkJS`, `jsperf`, or `fastest`. 2. **Utilizing web workers**: Web workers can be used to run multiple benchmarks concurrently, improving overall throughput and reducing test time. 3. **Employing parallel processing**: Utilize techniques like multi-threading or concurrent execution to speed up benchmarking. Keep in mind that the choice of approach depends on the specific requirements and goals of your benchmarking project.
Related benchmarks:
Object.keys(object).includes(key) vs key in object
array includes vs object[key] vs key in object
array includes vs object key -1
array find vs object key
Comments
Confirm delete:
Do you really want to delete benchmark?