Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Which equals operator (== vs ===) is faster? 3
(version: 0)
Is there a performance benefit to replacing == with ===?
Comparing performance of:
test equality vs test strict equality
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
test equality
var fun = () => { for (let i = 0; i < 1000000; i++) { if ((i + 'yes') == 95653) { return true; } } }; fun();
test strict equality
var fun = () => { for (let i = 0; i < 1000000; i++) { if ((i + 'yes') === 95653) { return true; } } }; fun();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
test equality
test strict equality
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Chrome OS 14541.0.0
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
test equality
5.9 Ops/sec
test strict equality
17.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
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: 1. **`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();`** * This option uses the loose equality operator (`==`) to compare `i + 'yes'` with a numeric value `95653`. 2. **`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();`** * This option uses the strict equality operator (`===`) to compare `i + 'yes'` with a numeric value `95653`. **Pros and Cons** * **Using loose equality (`==`)**: + Pros: easier to read and write, less prone to type errors. + Cons: can lead to unexpected behavior when comparing different data types (e.g., strings vs. numbers). * **Using strict equality (`===`)**: + Pros: provides more precise control over comparisons, reduces the risk of type-related errors. + Cons: more verbose and may be less readable for some developers. **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: 1. Use different types of variables instead of `let` (e.g., `const`, `var`, `let` with different initial values). 2. Change the comparison values or expressions to test other equality-related scenarios. 3. Add more iterations or variations in the loop to increase the benchmark's complexity and relevance. 4. Experiment with different browsers, Node.js versions, or environments to see how performance varies across different platforms. 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.
Related benchmarks:
Which equals operator (== vs ===) is faster?
Which equals operator (== vs ===) is faster?
Which equals operator (== vs ===) is faster?
Which equals operator (== vs ===) is faster2?
Which equals operator (== with type coercion vs ===) is faster?
Comments
Confirm delete:
Do you really want to delete benchmark?