Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Which equals operator (== vs === vs Object.is) is faster?
(version: 0)
Is there a performance benefit to replacing == with ===?
Comparing performance of:
test equality vs test strict equality vs Object
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
test equality
var n = 0; while(true) { n++; if(n==100000) break; }
test strict equality
var n = 0; while(true) { n++; if(n===100000) break; }
Object
var n = 0; while(true) { n++; if(Object.is(n,100000)) break; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
test equality
test strict equality
Object
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
test equality
38019.5 Ops/sec
test strict equality
38766.2 Ops/sec
Object
10882.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided JSON represents a benchmark test case that compares the performance of three different equality operators in JavaScript: `==`, `===`, and `Object.is()`. The tests are designed to measure which operator is faster for a specific use case, where a variable `n` is incremented until it reaches 100,000. **Options compared** There are three options being compared: 1. **`==` (loose equality)** 2. **`===` (strict equality)** 3. **`Object.is()`** (from the JavaScript built-in `Object` prototype) Each option has its own pros and cons: * `==` is a loose equality operator that checks for value equality, but not type equality. It can lead to unexpected behavior when comparing different data types. * `===` is a strict equality operator that checks both value and type equality. It's generally safer than `==`, but can also be slower due to the additional type checking. * `Object.is()` is a built-in function that performs a deep comparison of two values, including their types. It's considered more accurate than `==` or `===`, but may also be slower. **Other considerations** When choosing between these operators, consider the following: * If you need to compare different data types (e.g., numbers and strings), `===` might be a better choice. * If you're working with legacy code that uses `==`, it's essential to understand its limitations and potential issues. * When performance is critical, profiling tools can help determine which operator is actually being used by the browser. **Libraries and special JS features** None of the provided test cases use any libraries or special JavaScript features. The benchmarks only rely on standard JavaScript operators and built-in functions. **Benchmark preparation code** The `Script Preparation Code` and `Html Preparation Code` fields are empty, which means that the benchmark doesn't require any additional setup beyond what's already included in the benchmark definition. Overall, this benchmark test case provides a useful comparison of three equality operators in JavaScript, helping developers understand their performance characteristics and choose the best operator for specific use cases.
Related benchmarks:
Which equals operator (== vs ===) is faster?
Which equals operator (== vs ===) is faster?
Which equals operator (== vs ===) is faster2?
Which equals operator (== vs ===) is faster? with object.is
Comments
Confirm delete:
Do you really want to delete benchmark?