Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Which equals operator (== vs ===) is faster (different types)?
(version: 0)
Is there a performance benefit to replacing == with ===?
Comparing performance of:
test equality vs test strict equality
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
test equality
var n = 0; while(n <= 100001) { n++; if(n=="100000") break; }
test strict equality
var n = 0; while(n < 100001) { n++; if(n==="100000") break; }
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
test equality
3223.1 Ops/sec
test strict equality
26591.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **What is being tested?** The benchmark measures the performance difference between two types of comparison operators: `==` (loose equality) and `===` (strict equality). The test cases use different variable declarations, which affect how the JavaScript engine evaluates these comparisons. In summary, we're comparing: 1. Loose equality (`==`) using a number variable (`var n = 0;`) 2. Strict equality (`===`) using a string literal in a numerical context (`if(n==\"100000\")`) **Options being compared** The benchmark is testing two approaches: 1. **Loose Equality (`==`)** * Pros: Simple, widely supported by browsers. * Cons: + Can lead to unexpected behavior due to type coercion. + May not perform as well as strict equality. 2. **Strict Equality (`===`)** * Pros: More predictable, better performance. * Cons: + Less supported by older browsers (pre-ES6). + Requires explicit declaration of variable types. **Other considerations** The benchmark doesn't account for other factors that might affect the outcome, such as: * The number of iterations in the loop * Memory allocation and deallocation during each iteration * Garbage collection frequency Keep in mind that these variations might impact the results. **Library usage** None. This benchmark doesn't use any external libraries. **Special JavaScript features or syntax** This benchmark uses: 1. **ES6 strict equality (`===`)**: The comparison operator `==` is replaced with `===`, which ensures that both operands are of the same type. 2. **Type coercion**: In the loose equality test, the string literal `"100000"` is compared to a number variable `n`. This can lead to unexpected behavior due to type coercion. **Other alternatives** To create a similar benchmark, you could consider testing other comparison operators or scenarios, such as: * Loose and strict equality with different data types (e.g., strings, numbers, booleans) * Equality comparisons in more complex contexts, like object comparisons * Comparison performance under different CPU architectures or caching mechanisms
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?