Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
fuck you proxy logger perf
(version: 0)
Comparing performance of:
shitty vs even shittier
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
class Log { buffer = ""; bufferCounter = 0; log(level, message, tag) { const style = ""; this.buffer += `<log severity="${level}" style="${style}">[123][${tag}] ${message}</log>\n`; this.bufferCounter++; this.flushBufferIfNecessary(); } info(message, tag) { this.log(1, message, tag); } flushBufferIfNecessary(force = false) { if (this.bufferCounter >= 100 || force) { if (this.buffer.length > 0) { console.log(this.buffer); } this.buffer = ""; this.bufferCounter = 0; } } postTick() { this.flushBufferIfNecessary(true); } } var logger = new Log(); console.log(logger); var getProxyLogger = (tag) => new Proxy(logger, { get(target, prop) { const origMethod = target[prop]; if (typeof origMethod == 'function' && prop == "log") { return function(...args) { args[2] = tag; let result = origMethod.apply(target, args) return result } } return origMethod; } }); var logger2 = getProxyLogger("abc")
Tests:
shitty
logger.info("test");
even shittier
logger2.info("test")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
shitty
even shittier
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):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmark on the MeasureThat.net website. The benchmark is designed to measure the performance of two logging functions: `logger.info()` and `logger2.info()`. The goal is to compare the execution speed and efficiency of these two logging functions. **Script Preparation Code Analysis** The Script Preparation Code defines a custom logging class called `Log` with several methods: 1. `log(level, message, tag)`: logs a message with the specified level, style, and tag. 2. `info(message, tag)`: calls `log(1, message, tag)` to log an info-level message. 3. `flushBufferIfNecessary(force = false)`: flushes the buffer if it has reached a certain size or if forced to do so. 4. `postTick()`: called repeatedly by Node.js to flush the buffer. The script also defines a proxy function `getProxyLogger` that intercepts method calls on the `Log` instance, allowing for custom behavior when logging messages. In this case, it modifies the log level and tag of the message being logged. **Options Compared** Two options are compared in this benchmark: 1. **`logger.info()`**: uses the original logging function with default settings. 2. **`logger2.info()`**: uses a proxy function that intercepts and modifies the log level and tag of the message being logged. **Pros and Cons of Each Approach** **`logger.info()`**: Pros: Simple, straightforward implementation; does not introduce additional overhead or complexity. Cons: May be slower due to the custom behavior introduced by `getProxyLogger`. **`logger2.info()`**: Pros: Allows for customizing log levels and tags without modifying the original logging function. Cons: Introduces additional complexity and potential performance overhead due to the proxy function. **Other Considerations** * The benchmark uses a fixed buffer size (100) for both logging functions, which may impact performance. * Node.js's built-in `console.log()` function is not used in this benchmark, so it does not provide a direct comparison. However, it is likely that using `console.log()` would have similar performance characteristics to the custom logging functions. **Library and Special JS Feature** The `Proxy` object is used to implement the proxy function `getProxyLogger`. The purpose of `Proxy` is to create a transparent proxy object that intercepts property accesses and returns a new value. In this case, it allows for customizing the behavior of method calls on the `Log` instance. **Test Case Analysis** The two test cases are designed to execute the logging functions with identical input parameters (`"test"`). The benchmark measures the execution speed of both functions in terms of the number of executions per second. By comparing the performance of these two options, this benchmark aims to answer the question: "Is customizing log levels and tags through a proxy function an effective way to improve performance?"
Related benchmarks:
console.log test
Proxies
console-1928158917583
console-19281589175831
Comments
Confirm delete:
Do you really want to delete benchmark?