var a = 0
function f () {
a += 0.01
if (a < 0) {
throw new Error()
}
}
f()
try {
f()
} catch (e) {
console.log(e)
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
plain | |
try catch |
Test name | Executions per second |
---|---|
plain | 3244800.0 Ops/sec |
try catch | 3268037.8 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks and explore what's being tested on MeasureThat.net.
The benchmark definition JSON represents two test cases:
Script Preparation Code
var a = 0;
function f() {
a += 0.01;
if (a < 0) {
throw new Error();
}
}
This code defines a function f()
that increments a variable a
by 0.01 every time it's called. If a
ever becomes negative, an error is thrown.
Options being compared
The benchmark compares two approaches:
f()
function without any try-catch block.f()
in a try-catch block, which catches and logs any errors thrown by the function.Pros and Cons
Library usage
There is no explicit library mentioned in the benchmark definition. However, it's likely that MeasureThat.net uses a hidden library or framework to execute the benchmarks and provide the results.
Special JS features/syntax
None are explicitly mentioned. The code uses standard JavaScript syntax and features.
Now, let's look at the individual test cases:
f()
function without any try-catch block.f()
in a try-catch block, which catches and logs any errors thrown by the function.Other alternatives
Some alternative approaches could be explored, such as:
f()
function, simply execute some no-op code (e.g., a constant value) to test the function's overhead.f()
function in a loop to simulate repeated executions and measure the overhead.These alternative approaches might provide additional insights into the performance characteristics of the f()
function, but they would require modifications to the benchmark definition and execution code.
That's a summary of what's being tested on MeasureThat.net!