Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
__proto__ vs. create
(version: 0)
Comparing performance of:
one vs create
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = null; var i = 0;
Tests:
one
let p = {idx : i}; obj = {idx : -i, __proto__ : p}; ++i;
create
let p = {idx : i}; Object.create(p, {idx : {value : -i}}); ++i;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
one
create
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 break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark is defined by two test cases: 1. `"one"`: This test case creates an object `p` with a property `idx`, which is initialized to the value of `i`. Then, it sets up another object `obj` that inherits from `p` using the `__proto__` keyword. 2. `"create"`: This test case does essentially the same thing as `"one"`, but instead of using the `__proto__` keyword, it uses the `Object.create()` method to create a new object that inherits from `p`. **What's being tested?** The benchmark is testing the performance difference between using the `__proto__` keyword and the `Object.create()` method to create an object that inherits from another object. The specific properties of interest are: * The overhead of creating and accessing objects using `__proto__` * The overhead of creating and accessing objects using `Object.create()` **Options being compared** The two options being compared are: 1. `__proto__` keyword 2. `Object.create()` method **Pros and Cons of each approach:** 1. **`__proto__` keyword** * Pros: + Simple and concise syntax + Fast access to inherited properties * Cons: + May have performance overhead due to the need for property lookup 2. `Object.create()` method` * Pros: + More explicit and predictable behavior + Allows for easy creation of objects with custom prototypes * Cons: + Slower access to inherited properties compared to `__proto__` **Library usage** None of the test cases use any external libraries. **Special JS feature or syntax** The only special syntax used in these benchmark is the `++i` increment operator, which increments the variable `i` and returns its new value. This is a simple way to create an array of iterations for the benchmark. **Other alternatives** If you wanted to write this benchmark using a different approach, here are some alternative options: 1. Use `Object.getPrototypeOf()` and `Object.setPrototypeOf()` methods to create objects with custom prototypes. 2. Implement your own object creation and inheritance logic in native code (e.g., using assembly language). 3. Use a library like `benchmark.js` or `jsperf` that provides more advanced benchmarking features. However, the current implementation using `__proto__` and `Object.create()` is straightforward and easy to understand, making it an excellent choice for this specific benchmark.
Related benchmarks:
Optional chaining vs Empty method
Object.create(null) vs Object literal
javascript new vs Object.create 2
javascript new vs Object.create 3
Array isArray vs Object.prototype
Comments
Confirm delete:
Do you really want to delete benchmark?