Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
js private field - es2017
(version: 1)
Comparing performance of:
private vs public
Created:
7 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var _MyClass__propertyOne, _MyClass__propertyTwo, _MyClass__sum; class MyClass { constructor() { _MyClass__propertyOne.set(this, 1); _MyClass__propertyTwo.set(this, 2); _MyClass__sum.set(this, 0); } sumProperties() { for (let i = 0; i < 10000; i++) __classPrivateFieldSet(this, _MyClass__sum, __classPrivateFieldGet(this, _MyClass__sum, "f") + (__classPrivateFieldGet(this, _MyClass__propertyOne, "f") + __classPrivateFieldGet(this, _MyClass__propertyTwo, "f")), "f"); } } _MyClass__propertyOne = new WeakMap(), _MyClass__propertyTwo = new WeakMap(), _MyClass__sum = new WeakMap(); class MyClassPublic { _propertyOne = 1; _propertyTwo = 2; _sum = 0; sumProperties() { for (let i = 0; i < 10_000; i++) this._sum += this._propertyOne + this._propertyTwo; } }
Tests:
private
new MyClass().sumProperties();
public
new MyClassPublic().sumProperties();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
private
public
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0
Browser/OS:
Firefox 143 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
private
1357.6 Ops/sec
public
137211.7 Ops/sec
Related benchmarks:
ES6 property get & getter function & direct access to object attribute
Class Accessor vs Method v2
field vs property2
field vs property2gdfgdfgdf
field vs property23
field vs property2344
Public vs Private properties
ES6 property get & getter function & direct access to object attribute
js private field - es2017 v2
Comments
Confirm delete:
Do you really want to delete benchmark?