Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Proxy overhead test vs classes
(version: 0)
Comparing performance of:
Baseline Map object vs Object vs Subclass vs Proxy
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var text = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?" var simple_map = new Map(); var simple_obj = {}; class DefaultMap extends Map { constructor(defaultValue) { super(); this.defaultValue = defaultValue; } get(key) { if (!this.has(key)) { this.set(key, this.defaultValue); } return super.get(key); } } var dm = new DefaultMap(0) let base_obj = {}; var proxy_obj = new Proxy(base_obj, { get: function(target, prop, receiver) { return Reflect.get(target, prop, receiver) ?? 0; }, });
Tests:
Baseline Map object
for (const c of text) { simple_map.set(c, (simple_map.get(c) ?? 0) + 1) }
Object
for (const c of text) { simple_obj[c] = (simple_obj[c] ?? 0) + 1 }
Subclass
for (const c of text) { dm.set(c, dm.get(c)+1) }
Proxy
for (const c of text) { proxy_obj[c] += 1; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Baseline Map object
Object
Subclass
Proxy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Baseline Map object
42875.9 Ops/sec
Object
49416.3 Ops/sec
Subclass
30911.5 Ops/sec
Proxy
3225.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **Benchmark Overview** The benchmark, called "Proxy overhead test vs classes", aims to compare the performance of three approaches: 1. A built-in JavaScript object (baseline) 2. A subclassing approach 3. A proxy-based approach Each approach is used to iterate over a large string (`text`) and update its frequency count in various ways. **Options Compared** The benchmark compares four options: 1. **Baseline Object**: Using a plain JavaScript object (`simple_obj`) to store the frequency counts. 2. **Subclassing**: Creating a subclass of `Map` (`DefaultMap`) that extends the built-in `Map` and provides additional logic for setting default values. 3. **Proxy**: Using a proxy object (`proxy_obj`) to intercept getter requests on the underlying object. **Pros and Cons** 1. **Baseline Object**: * Pros: Simple, straightforward implementation, no additional overhead. * Cons: May not provide optimal performance due to frequent property lookups. 2. **Subclassing**: * Pros: Provides a custom solution for setting default values, can be optimized for performance. * Cons: Requires creating a new class, may have additional overhead due to inheritance and method calls. 3. **Proxy**: * Pros: Allows for fine-grained control over getter behavior, can provide optimal performance by intercepting requests. * Cons: Adds significant overhead due to the creation of proxy objects. **Library** The benchmark uses the `Reflect` object to implement the proxy-based approach. The `Reflect.get()` method is used to retrieve values from the target object, and `Reflect.set()` is not explicitly mentioned, but it's implied that the `set()` behavior is being intercepted by the proxy. **Special JS Features or Syntax** The benchmark uses some advanced JavaScript features: * **Proxy**: The use of proxies allows for fine-grained control over getter behavior. * **Subclassing**: Creating a subclass of `Map` to extend its behavior. * **Spread Operator (`??`)**: Used in the baseline object implementation to provide default values. **Alternatives** Other alternatives could be explored, such as: 1. Using a custom implementation of `Map` or `Object` with optimized performance characteristics. 2. Utilizing native WebAssembly (WASM) for improved performance and efficiency. 3. Implementing the benchmark using a language like C++ for maximum optimization. Keep in mind that these alternatives would require significant changes to the benchmark code and may not be suitable for production use without thorough testing and optimization.
Related benchmarks:
regex vs includes speed comparison
Spilt() vs Substring()
RegEx.test vs. String.includes vs. String.match (long)
RegEx.test vs. String.includes vs. String.match vs String.indexOf - Long String
Comments
Confirm delete:
Do you really want to delete benchmark?