Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
public vs private vs symbol
(version: 0)
Comparing performance of:
public vs private vs local vs private public vs symbol
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const zx = Symbol('zx'); const zy = Symbol('zy'); const fsq = Symbol('fsq'); const zx2 = Symbol('zx2'); const zy2 = Symbol('zy2'); const n = Symbol('n'); class Benchmark { #zx; #zy; #fsq; #zx2; #zy2; #n; #private = {}; run_private(cx, cy) { this.#zx = 0; this.#zy = 0; for (this.#n = 0; this.#n < 256; this.#n++) { this.#zx2 = this.#zx * this.#zx; this.#zy2 = this.#zy * this.#zy; this.#zy = 2 * this.#zx * this.#zy + cy; this.#zx = this.#zx2 - this.#zy2 + cx; this.#fsq = this.#zx2 + this.#zy2; if (this.#fsq > 4) return false; } return true; } run_private_public(cx, cy) { const p = this.#private; p.zx = 0; p.zy = 0; for (p.n = 0; p.n < 256; p.n++) { p.zx2 = p.zx * p.zx; p.zy2 = p.zy * p.zy; p.zy = 2 * p.zx * p.zy + cy; p.zx = p.zx2 - p.zy2 + cx; p.fsq = p.zx2 + p.zy2; if (p.fsq > 4) return false; } return true; } run_public(cx, cy) { this.zx = 0; this.zy = 0; for (this.n = 0; this.n < 256; this.n++) { this.zx2 = this.zx * this.zx; this.zy2 = this.zy * this.zy; this.zy = 2 * this.zx * this.zy + cy; this.zx = this.zx2 - this.zy2 + cx; this.fsq = this.zx2 + this.zy2; if (this.fsq > 4) return false; } return true; } run_symbol(cx, cy) { this[zx] = 0; this[zy] = 0; for (this[n] = 0; this[n] < 256; this[n]++) { this[zx2] = this[zx] * this[zx]; this[zy2] = this[zy] * this[zy]; this[zy] = 2 * this[zx] * this[zy] + cy; this[zx] = this[zx2] - this[zy2] + cx; this[fsq] = this[zx2] + this[zy2]; if (this[fsq] > 4) return false; } return true; } run_local(cx, cy) { let zx = 0; let zy = 0; for (let n = 0; n < 256; n++) { let zx2 = zx * zx; let zy2 = zy * zy; zy = 2 * zx * zy + cy; zx = zx2 - zy2 + cx; let fsq = zx2 + zy2; if (fsq > 4) return false; } return true; } } var benchmark = new Benchmark();
Tests:
public
benchmark.run_public(-0.5, 0.1);
private
benchmark.run_private(-0.5, 0.1);
local
benchmark.run_local(-0.5, 0.1);
private public
benchmark.run_private_public(-0.5, 0.1);
symbol
benchmark.run_symbol(-0.5, 0.1)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
public
private
local
private public
symbol
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):
Measuring the performance of different JavaScript execution contexts can be an interesting topic. **Benchmark Definition** The provided JSON represents a benchmark that measures the performance of four different JavaScript execution contexts: 1. **Public**: The code is executed in the global scope, with all variables defined at the top-level. 2. **Private**: The code is executed in an object's `__proto__` property, which is not directly accessible from the code. 3. **Symbol**: The code uses symbols as property names to access and modify variables. 4. **Local**: The code is executed in a local scope, with all variables defined within the function. **Options Compared** The benchmark compares the performance of each execution context: * `run_private` (Private): Accessing and modifying variables using object syntax (`benchmark.run_private(-0.5, 0.1);`) * `run_private_public` (Private Public): Using both object syntax and symbol notation to access and modify variables (`benchmark.run_private_public(-0.5, 0.1);`) * `run_symbol` (Symbol): Using symbols as property names to access and modify variables (`benchmark.run_symbol(-0.5, 0.1);`) * `run_local` (Local): Accessing and modifying variables within a local scope (`benchmark.run_local(-0.5, 0.1);`) **Latest Benchmark Result** The latest benchmark result shows the performance of each execution context: | Test Name | ExecutionsPerSecond | | --- | --- | | Local | 764383.75 | | Public | 471426.8125 | | Private Public | 422979.96875 | | Symbol | 363846.375 | The results suggest that executing code in a local scope (Local) is the fastest, followed by executing code using object syntax (Public), then symbol notation (Symbol), and finally executing code using both object syntax and symbol notation (Private Public). **Interpretation** The performance differences between these execution contexts can be attributed to various factors: * **Scoping**: Local variables are in scope only within the function, reducing overhead compared to global or object properties. * **Symbolic Access**: Symbols provide a way to access variables without using string literals, which may reduce lookup times. * **Object Syntax**: Object syntax provides a more straightforward way of accessing and modifying properties, but may introduce additional overhead due to string comparison. The results can be useful for identifying performance bottlenecks in JavaScript applications, particularly when working with large datasets or complex algorithms.
Related benchmarks:
noop function call vs conditional
Array.filter vs. raw for-loop vs. for..of vs. Array.reduce vs. generator spread 2
public vs private vs local
Comparison of classes vs prototypes vs object literals also including the inheritance
Comments
Confirm delete:
Do you really want to delete benchmark?