Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Hidden class test
(version: 10)
Hidden class test
Comparing performance of:
case1 vs case2 vs case3
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function addPoint1(x, y) { this.x = x; this.y = y; return this; } function addPoint2(x, y) { this.x = x; this.y = y; this.z = 0; return this; }
Tests:
case1
var p1 = new addPoint1(1, 2); var p2 = new addPoint1(3, 4); var p3 = new addPoint1(5, 6); var p4 = new addPoint1(7, 8); var p5 = new addPoint1(17, 8); p1.z = 1; p2.z = 2; p3.z = 3; p4.z = 3; p5.z = 3; console.log(p1.z, p2.z, p3.z, p4.z, p5.z);
case2
var p1 = new addPoint1(1, 2); var p2 = new addPoint1(3, 4); var p3 = new addPoint1(5, 6); var p4 = new addPoint1(7, 8); var p5 = new addPoint1(17, 8); p1.z = 1; p2.a = 2; p3.b = 3; p4.c = 2; p5.d = 3; console.log(p1.z, p2.a, p3.b, p4.c, p5.d);
case3
var p1 = new addPoint2(1, 2); var p2 = new addPoint2(3, 4); var p3 = new addPoint2(5, 6); var p4 = new addPoint2(7, 8); var p5 = new addPoint2(17, 8); p1.z = 1; p2.z = 2; p3.z = 3; p4.z = 3; p5.z = 3; console.log(p1.z, p2.z, p3.z, p4.z, p5.z);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
case1
case2
case3
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
case1
109960.2 Ops/sec
case2
103175.3 Ops/sec
case3
103430.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what is being tested on MeasureThat.net and explain the different approaches compared. **Benchmark Definition** The benchmark definition provided is a JavaScript code that creates instances of two classes: `addPoint1` and `addPoint2`. The classes have properties `x`, `y`, `z`, `a`, `b`, `c`, and `d`. **Script Preparation Code** The script preparation code defines the `addPoint1` and `addPoint2` classes. These classes have constructors that initialize the instance variables with values from the function arguments. ```javascript function addPoint1(x, y) { this.x = x; this.y = y; return this; } function addPoint2(x, y) { this.x = x; this.y = y; this.z = 0; return this; } ``` **Hidden Classes** The `addPoint1` class uses a technique called "hidden classes" to optimize performance. In traditional JavaScript classes, the browser has to keep track of all possible property combinations at runtime. By using a hidden class, the browser can store a single class object that contains metadata about the instance variables and their values. **Options Compared** The benchmark compares three different approaches: 1. **Case 1**: `addPoint1` with no additional properties (`a`, `b`, etc.). This is similar to the traditional JavaScript class implementation. 2. **Case 2**: `addPoint1` with additional properties (`a`, `b`, etc.), but without using hidden classes. 3. **Case 3**: `addPoint2`, which does not use hidden classes. **Pros and Cons** * **Case 1 (addPoint1)**: + Pros: Easy to implement, well-understood by developers. + Cons: May lead to slower performance due to the overhead of traditional JavaScript class implementation. * **Case 2 (addPoint1 with additional properties)**: + Pros: Still easy to implement, but may have better performance compared to Case 1. + Cons: Requires careful consideration of property combinations and metadata storage. * **Case 3 (addPoint2)**: + Pros: Optimized for hidden classes, which can lead to faster performance. + Cons: May require more complex implementation, and the benefits may be subtle. **Other Considerations** * **Library Usage**: The benchmark uses no external libraries. If it were to use a library, it might impact the results. * **Special JS Features or Syntax**: There are no special JavaScript features or syntax used in this benchmark. **Alternatives** If you wanted to create similar benchmarks for other languages, you could use different approaches: * For example, if you wanted to test the performance of Java's class loading mechanism, you could compare implementations using: + Traditional Java class loading (no optimizations). + Ahead-of-time compilation with hidden classes. + Just-in-time compilation without hidden classes. Keep in mind that these alternatives would require careful consideration of language-specific features and mechanisms.
Related benchmarks:
Spread vs Object.assign (modify ) vs Object.assign (new)
Spread vs Assign benchmark
Spread vs Assign benchmark2
Spread vs Assign benchmark 2
Object spread
Comments
Confirm delete:
Do you really want to delete benchmark?