Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Direct access vs prototype lookup
(version: 0)
Comparing performance of:
Direct vs Semi-proto vs Proto
Created:
6 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var LD = Array(100).fill(1).map(() => ({ x: 1, y: 2 })) var P1 = { x: 1 } var LP1 = Array(100).fill(1).map(() => { var A = Object.create(P1); A.y = 2; return A }) var P2 = { x: 1, y: 2 } var LP2 = Array(100).fill(1).map(() => Object.create(P2))
Tests:
Direct
var S = 0 for (let x = 0; x < 100; x++) { let next = LD[x] S = (S + next.x + next.y) } console.log(S)
Semi-proto
var S = 0 for (let x = 0; x < 100; x++) { let next = LP1[x] S = (S + next.x + next.y) } console.log(S)
Proto
var S = 0 for (let x = 0; x < 100; x++) { let next = LP2[x] S = (S + next.x + next.y) } console.log(S)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Direct
Semi-proto
Proto
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 YaBrowser/24.7.0.0 Safari/537.36
Browser/OS:
Yandex Browser 24 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Direct
118258.9 Ops/sec
Semi-proto
122487.3 Ops/sec
Proto
122830.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmark called "Direct access vs prototype lookup". The benchmark compares three approaches: 1. **Direct access**: This approach uses direct property access to access elements of the `LD` array, which is created using the `Array.prototype.fill()` and `Array.prototype.map()` methods. 2. **Semi-proto (Semi-Prototype)**: This approach uses a mix of prototype inheritance and object creation to create objects that inherit properties from a base object `P1`, while still having their own `y` property set to 2 using `Object.create()`. 3. **Proto**: This approach uses the same semi-proto approach as above, but with a different way of creating the objects. **Options Comparison** Here's a brief overview of each option: * **Direct access**: This approach is simple and efficient, as it avoids the overhead of object creation and prototype lookup. + Pros: Fast execution, minimal memory allocation. + Cons: May not work well with large datasets or complex object hierarchies. * **Semi-proto (Semi-Prototype)**: This approach balances between direct access and proto-based object creation, offering a compromise between the two. + Pros: Offers better performance than pure proto-based approaches, but still avoids deep prototype lookup. + Cons: May require more memory allocation due to object creation, and can lead to slower execution times in some cases. * **Proto**: This approach uses a similar semi-proto strategy as above, with some differences in the way objects are created. + Pros: Similar benefits to semi-proto, but with some tweaks to optimize performance. + Cons: May require more fine-tuning and optimization to achieve optimal results. **Library Usage** The benchmark uses several libraries and features: * **Array.prototype.fill()**: Used to create an array of 100 elements, filled with the value 1. * **Array.prototype.map()**: Used to map over the array and create new objects for each element. * **Object.create()**: Used to create objects that inherit properties from a base object. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in this benchmark, apart from: * **let x = 0;` loops: Used for loop iterations, which can be optimized by some engines. * `const` keyword is not explicitly mentioned but could be considered for the variable declarations. **Other Alternatives** If you'd like to explore alternative approaches or optimizations for similar benchmarks, here are a few options: * **Use of typed arrays**: Using typed arrays (e.g., Int8Array) instead of regular arrays might offer better performance in certain scenarios. * **Iteration using `for...of` loops**: Instead of traditional `for...in` loops, using `for...of` loops can provide better performance and more concise code. * **Reducing object creation overhead**: Optimizing object creation and reuse strategies might lead to improved performance results. Please note that the performance differences between these approaches may vary depending on the specific use case, engine version, and other factors.
Related benchmarks:
Object.assign vs apread
undefined vs evaluation vs hasOwnProperty
"this" property vs. closure upvalue
in vs Object.hasOwn vs Object.prototype.hasOwnProperty
Comments
Confirm delete:
Do you really want to delete benchmark?