var fun = () => {
for (let i = 0; i < 1000000; i++) {
if ((i + 'yes') == 95653) {
return true;
}
}
};
fun();
var fun = () => {
for (let i = 0; i < 1000000; i++) {
if ((i + 'yes') === 95653) {
return true;
}
}
};
fun();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
test equality | |
test strict equality |
Test name | Executions per second |
---|---|
test equality | 5.9 Ops/sec |
test strict equality | 17.0 Ops/sec |
Measuring the performance of JavaScript's equality operators can be an interesting benchmark.
Benchmark Definition
The benchmark is designed to test which equality operator (==
or ===
) is faster. The script preparation code is empty, and the HTML preparation code is also empty.
Options compared
Two options are being compared:
var fun = () => {\r\n for (let i = 0; i < 1000000; i++) {\r\n if ((i + 'yes') == 95653) {\r\n return true;\r\n }\r\n }\r\n};\r\nfun();
==
) to compare i + 'yes'
with a numeric value 95653
.var fun = () => {\r\n for (let i = 0; i < 1000000; i++) {\r\n if ((i + 'yes') === 95653) {\r\n return true;\r\n }\r\n }\r\n};\r\nfun();
===
) to compare i + 'yes'
with a numeric value 95653
.Pros and Cons
==
):===
):Library
There is no specific library being used in this benchmark. The code only utilizes built-in JavaScript functionality.
Special JS feature or syntax
The benchmark uses a modern JavaScript feature: Arrow functions (=>
), introduced in ECMAScript 2015 (ES6). This allows for concise and readable code, but may not be supported by older browsers or versions of Node.js.
Other alternatives
If you wanted to modify this benchmark, here are some alternative approaches:
let
(e.g., const
, var
, let
with different initial values).Keep in mind that this is just one possible set of options, and there are many ways to modify a benchmark while still maintaining its core purpose.