Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
oop performance test
(version: 0)
Comparing performance of:
oloo vs direct properties vs classes
Created:
8 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
// *class* defined in terms of OLOO var class1 = { set_property: function(name, value) { this.properties[name] = value; }, get_property: function(name) { return this.properties[name]; }, get_p: function() { return this.p; }, set_p: function(val) { this.p = val; } } function inst_class1() { var obj = Object.create(class1) obj.properties = {} obj.p = 0; return obj; } // just an object with it's own methods function inst_class2() { return { properties: {}, p: 0, set_property: function(name, value) { this.properties[name] = value; }, get_property: function(name) { return this.properties[name]; }, get_p: function() { return this.p; }, set_p: function(val) { this.p = val; } } } // es6 class class class3 { set_property(name, value) { this.properties[name] = value; } get_property(name) { return this.properties[name]; } get_p() { return this.p; } set_p(val) { this.p = val; } } function inst_class3() { var obj3 = new class3(); obj3.properties = {}; obj3.p = 0; return obj3 } // the test function test(obj) { var result = 0; for (var i = 0; i < N; i++) { obj.set_property(i, i*0.33); result += obj.get_property(i); obj.set_p(result); result += obj.get_p(); } return result; } var N = 1000000;
Tests:
oloo
var result = test(inst_class1());
direct properties
var result = test(inst_class2());
classes
var result = test(inst_class3());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
oloo
direct properties
classes
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 world of JavaScript microbenchmarks. **Benchmark Definition** The provided JSON represents a benchmark that tests the performance of three different approaches to create objects with methods: 1. **OLOO (Object Literal Object)**: An object created using `var class1 = { ... }`. 2. **Direct Properties**: An object created as an ordinary JavaScript object, e.g., `var obj = { properties: {}, p: 0 }`. 3. **ES6 Class**: A class defined using the ES6 syntax, e.g., `class class3 { set_property(name, value) { ... } }`. The benchmark consists of a test function `test(obj)` that: * Iterates over a loop (`N` times) * Sets and gets properties using each approach * Returns the result **Options Compared** The three approaches are compared in terms of performance. The options being tested are: * **OLOO (Object Literal Object)**: Creating an object with methods defined directly on the object literal. * **Direct Properties**: Creating an object as an ordinary JavaScript object and defining methods using dot notation (`obj.set_property(i, i * 0.33)`). * **ES6 Class**: Defining a class using the ES6 syntax and creating instances using `new`. **Pros and Cons of Each Approach** Here's a brief summary: 1. **OLOO (Object Literal Object)**: * Pros: Simple, concise syntax, no need for additional syntax. * Cons: May not be as intuitive or readable as other approaches. 2. **Direct Properties**: * Pros: Can be more readable and maintainable than OLOO, especially for simple objects. * Cons: May require more boilerplate code (e.g., `var obj = { ... }`). 3. **ES6 Class**: * Pros: More modern, expressive syntax, supports inheritance and other class features. * Cons: May be less familiar to developers who are not already comfortable with classes. **Library Used** There is no explicit library mentioned in the benchmark definition. However, the `Object.create()` method is used to create instances of the `class1` object, which is a built-in JavaScript method. **Special JS Features or Syntax** The ES6 class syntax is used here, but it's not explicitly tested for performance. The other approaches are more traditional and don't rely on specific features or syntax. **Other Alternatives** If you want to test alternative approaches, you might consider: * Using a library like Lodash or Underscore.js to provide functional programming utilities. * Exploring modern JavaScript features like async/await or decorators. * Investigating other object creation methods, such as `Object.assign()` or `Array.prototype.concat()`.
Related benchmarks:
oop performance test
oop performance test
oop performance test
"this" property vs. closure upvalue
Comments
Confirm delete:
Do you really want to delete benchmark?