const someOp = () => {
console.info('boi')
}
const ops = {
0: someOp,
1: () => null,
2: () => null,
3: someOp,
}
for (let i = 0; i < 4; i++) {
ops[i]();
}
const someOp = () => {
console.info('boi')
}
const enter = 0;
const exit = 3;
for (let i = 0; i < 4; i++) {
if (i === enter) {
someOp();
} else if (i === exit) {
someOp();
}
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object | |
If statement |
Test name | Executions per second |
---|---|
Object | 15598.1 Ops/sec |
If statement | 16128.7 Ops/sec |
Benchmark Explanation
The provided JSON represents two individual test cases for measuring the performance of JavaScript microbenchmarks on MeasureThat.net.
Test Case 1: Object Functions vs If Statements
In this test case, we have an object ops
with four properties (0-3) that call either a function someOp
or a no-op function. The someOp
function simply logs "boi" to the console. The test iterates through each property in the ops
object and calls its corresponding function.
Test Case 2: If Statement
In this test case, we have an if-else statement that checks if the current iteration index i
is equal to a specific value (either enter
or exit
). If it is, the someOp
function is called. The test iterates through each iteration of the loop and applies this condition.
Comparison of Approaches
In both test cases, we are comparing two approaches:
Library: console
In both test cases, we use the console
object to log messages to the console. The console.info()
function is used in Test Case 1 and not explicitly mentioned in Test Case 2, but it's implied that the same logging functionality would be needed.
Special JS Feature/Syntax: None Mentioned
There are no special JavaScript features or syntaxes being tested in these benchmarks.
Other Alternatives
If you wanted to test these benchmarks on different platforms, browsers, or devices, MeasureThat.net allows you to add additional metadata to the benchmark definition, such as:
You can also modify the Benchmark Definition
string to include custom logic or data structures to test specific scenarios.
Keep in mind that the results may vary depending on the platform, browser, and device being used.