Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
TEST Cache 1000 Objects
(version: 0)
Comparing performance of:
No Cache vs Cache vs Just get vs Some props
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
n = 1000 cache = []; function Person(i) { this.name = i; this.name1 = "asfs"; this.name2 = "asfs"; this.name3 = "asfs"; this.name4 = "asfs"; this.name5 = "asfs"; this.name6 = "asfs"; this.name7 = "asfs"; this.name8 = "asfs"; this.name9 = "asfs"; this.name91 = "asfs"; this.name92 = "asfs"; this.name93 = "asfs"; this.name94 = "asfs"; this.name95 = "asfs"; } for (var i = 0; i < n; i++) { cache[i] = new Person(i); }
Tests:
No Cache
var arr = []; for (var i = 0; i < n; i++) { arr[i] = new Person(i); }
Cache
var arr = []; for (var i = 0; i < n; i++) { arr[i] = cache[i]; arr[i].name = i; arr[i].name1 = "asfs"; arr[i].name2 = "asfs"; arr[i].name3 = "asfs"; arr[i].name4 = "asfs"; arr[i].name5 = "asfs"; arr[i].name6 = "asfs"; arr[i].name7 = "asfs"; arr[i].name8 = "asfs"; arr[i].name9 = "asfs"; arr[i].name91 = "asfs"; arr[i].name92 = "asfs"; arr[i].name93 = "asfs"; arr[i].name94 = "asfs"; arr[i].name95 = "asfs"; }
Just get
var arr = []; for (var i = 0; i < n; i++) { arr[i] = cache[i]; }
Some props
var arr = []; for (var i = 0; i < n; i++) { arr[i] = cache[i]; arr[i].name = i; arr[i].name1 = "asfs"; arr[i].name2 = "asfs"; arr[i].name3 = "asfs"; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
No Cache
Cache
Just get
Some props
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 benchmark. **Benchmark Purpose** The benchmark measures the performance of JavaScript object creation and property assignment in different scenarios. Specifically, it tests how quickly objects can be created and properties set on them using different approaches. **Script Preparation Code** The script preparation code creates a cache array with 1000 elements, each representing an instance of the `Person` constructor function. The `Person` constructor function sets multiple properties (with repeating names) on each object. **Benchmark Definitions** There are four benchmark definitions: 1. **No Cache**: This definition tests creating objects from scratch without reusing any existing cache. It creates a new array and populates it with 1000 new `Person` instances. 2. **Cache**: This definition tests reusing the cache array to create objects. It accesses elements in the cache array using indices, which presumably are already initialized with objects created earlier. 3. **Just get**: This definition is similar to the Cache definition but only accesses and sets properties on the object without re-creating it from scratch. 4. **Some props**: This definition is similar to the No Cache definition but only creates objects and sets some of their properties. **Library and Purpose** The `Person` constructor function uses a technique called "prototype chain" or " prototype inheritance". The library used here is the standard JavaScript prototype system, which allows functions to extend other functions by adding new properties to the object's prototype. In this case, the `Person` function extends the `Object.prototype` with additional properties. This means that when an instance of `Person` is created, it inherits those properties from its prototype chain. **Special JS Features and Syntax** The benchmark uses a feature called "for...of" loops (also known as the "iterable protocol") introduced in ECMAScript 2015 (ES6). These loops allow iterating over arrays, objects, or other iterable values. In this case, the benchmark uses a for loop to iterate over the cache array and create objects. **Other Considerations** When interpreting these results, consider the following: * The browser's garbage collector and memory management can impact performance. * Optimizations like inlining, caching, and speculative execution might affect results. * Different browsers or versions may behave differently due to differences in JavaScript engine implementation. **Alternative Benchmarks** To gain more insights into object creation and property assignment, you could explore alternative benchmarks: 1. **Array creation**: Create large arrays and measure the time it takes to create them using different methods (e.g., `new Array(n)` vs. `[...Array(n)].map(() => {})`). 2. **Object literal creation**: Measure the performance of creating objects with literals (e.g., `{ name: 'John', age: 30 }`) compared to function-based object creation. 3. **Property assignment**: Benchmark assigning properties on objects using different methods (e.g., `obj['name'] = 'John';` vs. `obj.name = 'John';`). Keep in mind that these alternative benchmarks would require updating the script preparation code and benchmark definitions accordingly. If you have any specific questions or would like to discuss further, feel free to ask!
Related benchmarks:
for-in iteration with and without cache
Benchmark of Object.keys multiple calls
Lru cache 50% hit ratio test
just another for loop performance
TestKey
Comments
Confirm delete:
Do you really want to delete benchmark?