Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
complex values
(version: 0)
Comparing performance of:
without indexing vs with indexing vs with set and array
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
without indexing
let obj = {} for(i=0; i<100000; i++){ let v = { g: i, v: i }; obj = { ...obj, i: v}; }
with indexing
let obj = {} for(i=0; i<100000; i++){ let v = { g: i, v: i }; obj[i] = v; }
with set and array
let objArray = [] let set1 = new Set(); for(i=0; i<100000; i++){ if(!set1.has(i)) { set1.add(i); let v = { g: `${i}`, v: i }; objArray.push(v); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
without indexing
with indexing
with set and array
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):
**Overview of Benchmark Tests** The provided benchmark tests measure the performance of JavaScript code in various scenarios, specifically focusing on object creation and array/indexing operations. There are three test cases: 1. **"without indexing"`**: This test case creates an object `obj` and iterates 100,000 times, adding a new property `v` to `obj`. The key `v` is created with two properties: `g` and `v`, where `g` takes the value of the loop iteration `i` and `v` takes the same value. 2. **"with indexing"`**: This test case creates an object `obj` and iterates 100,000 times, adding a new property `v` to `obj`. The key `v` is created with two properties: `g` and `v`, where `g` takes the value of the loop iteration `i`. 3. **"with set and array"`**: This test case creates an empty array `objArray` and iterates 100,000 times. If a new element `i` is not already in a set `set1`, it adds `i` to the set and creates a new object `v` with properties `g` and `v`. The object `v` is then pushed onto the array `objArray`. **Comparison of Options** The tests compare different approaches: * **Without indexing**: This approach uses dynamic property assignment (`obj = { ...obj, i: v }`) to add new properties to the object. This method can be slower because it involves additional overhead for creating a new property descriptor. * **With indexing**: This approach uses direct property assignment (`obj[i] = v`) to add new properties to the object. This method is generally faster because it avoids the overhead of creating a new property descriptor. * **With set and array**: This approach uses a set to keep track of added elements and pushes objects onto an array. This method can be slower due to the additional overhead of using a set and array operations. **Pros and Cons** Here are some pros and cons of each approach: * **Without indexing**: + Pros: Can handle dynamic property assignment, which may be useful in certain scenarios. + Cons: May be slower due to the additional overhead of creating a new property descriptor. * **With indexing**: + Pros: Generally faster than without indexing due to reduced overhead. + Cons: Limited flexibility for dynamic property assignment. * **With set and array**: + Pros: Can handle duplicate elements, but may be slower due to the additional overhead. + Cons: May not be suitable for all use cases where direct property assignment is sufficient. **Library Used** None of the tests explicitly use a library. However, it's worth noting that JavaScript engines like V8 (used by Chrome) and SpiderMonkey (used by Firefox) provide optimized implementations for certain operations, such as array indexing and object creation. **Special JS Feature/Syntax** There are no special JS features or syntax used in these benchmark tests. The code is written in standard JavaScript syntax. **Alternatives** If you're looking for alternatives to these benchmarks, consider the following: * **BenchJS**: A fast and accurate JavaScript benchmarking tool that provides detailed results and analysis. * **jsperf**: A popular JavaScript benchmarking framework that allows you to compare the performance of different code snippets. * **Benchmarking libraries like Benchmark.js**: Provides a simple way to write benchmarks for your own projects. Keep in mind that these alternatives may have different strengths and weaknesses compared to MeasureThat.net, but they can provide valuable insights into your code's performance.
Related benchmarks:
Math.pow vs ** vs * forcing floats vs bigint
parseInt(stringInt) vs +stringInt
fast absolute value (branched & branchless) vs abs
fast absolute value (branched & branchless) vs abs vs ** -1
math.abs vs branchless absolute val 2
Comments
Confirm delete:
Do you really want to delete benchmark?