Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
public vs private vs local
(version: 0)
Comparing performance of:
public vs private vs local vs private public
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
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_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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
public
private
local
private public
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):
I'll break down the provided benchmark definitions and results. **Benchmark Definition Overview** The provided benchmark measures the performance of three different approaches: `public`, `private`, and `local`. Each approach uses a simple algorithm to calculate a value, with varying levels of encapsulation. The test cases are designed to compare the execution time and throughput of each approach across multiple browsers and devices. **Options Compared** 1. **Public**: This approach exposes all variables directly accessible from outside the function. 2. **Private**: This approach uses an object with private properties (denoted by a `#` symbol) to encapsulate the variables. 3. **Local**: This approach uses only local variables, without any form of encapsulation. **Pros and Cons** 1. **Public**: * Pros: Easy to understand, simple implementation. * Cons: Variables can be accessed and modified unexpectedly, leading to potential bugs and security issues. 2. **Private**: * Pros: Encapsulates variables, reducing the risk of external interference or misuse. * Cons: Additional complexity introduced by using objects and private properties, which may make it harder to understand and maintain. 3. **Local**: * Pros: Simple implementation, no external dependencies. * Cons: No encapsulation, making it difficult to reuse code or maintain state between function calls. **Library Use** None of the benchmark test cases use a library, so there is no additional dependency to consider. **Special JS Features/ Syntax** The `#` symbol used in the private property syntax is not a standard JavaScript feature. It appears to be a custom notation used by MeasureThat.net or the creator of the benchmark definition. **Alternative Approaches** Other approaches that could be considered for this benchmark include: 1. **Immutable Data Structures**: Using immutable data structures, such as arrays or tuples, instead of objects and private properties. 2. **Functional Programming**: Using functional programming concepts, such as higher-order functions or closures, to encapsulate variables without using objects. 3. **Type Inference**: Using type inference features in modern JavaScript compilers or transpilers to reduce the need for explicit encapsulation. However, these alternative approaches would likely introduce additional complexity and may not be necessary for a simple benchmark like this one.
Related benchmarks:
class scope access - cache vs this
public vs private vs symbol
C vs F
Comparison of classes vs prototypes vs object literals also including the inheritance
Comments
Confirm delete:
Do you really want to delete benchmark?