Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
simple int vs string vs boolean comparison
(version: 0)
Comparing performance of:
int comparison vs string comparison vs check boolean
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
int comparison
const a = 1 const b = 1 return a == b
string comparison
const a = "Primary" const b = "Primary" return a == b
check boolean
const isPrimary = true const isQuaternary = false if ( isPrimary ) { return isPrimary } else { return isQuaternary }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
int comparison
string comparison
check boolean
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
int comparison
175022816.0 Ops/sec
string comparison
163424256.0 Ops/sec
check boolean
119375504.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring JavaScript performance is an essential task for any developer, and MeasureThat.net provides a great platform to do so. **Benchmark Definition** The provided benchmark definition measures the execution time of three different types of comparisons: 1. **Integer comparison**: This test compares two integers (`const a = 1` and `const b = 1`) using the `==` operator. 2. **String comparison**: This test compares two strings (`const a = "Primary"` and `const b = "Primary"`) using the `==` operator. 3. **Boolean check**: This test checks if a boolean value (`const isPrimary = true` and `const isQuaternary = false`) is true or false, but with a twist. It uses an `if-else` statement to evaluate the condition and returns either `isPrimary` or `isQuaternary`. However, the actual logic inside the `if` block is unnecessary and just returns the same value as `isPrimary`, making this test more about evaluating a boolean expression than comparing values. **Comparison options** In each of these tests, there are two options being compared: * **Raw comparison**: This option uses the raw `==` operator to compare the values. * **Optimized comparison**: MeasureThat.net likely has optimized comparisons that take into account the types of values being compared. For example, comparing integers is typically faster than comparing strings. **Pros and Cons** Here are some pros and cons for each comparison option: 1. **Raw comparison (==)** * Pros: Simple to implement, widely supported. * Cons: May not be optimized for performance, can lead to slower execution times. 2. **Optimized comparison** * Pros: Optimized for performance, may be faster than raw comparison. * Cons: Less flexible, may not support all types of comparisons. **Libraries and special features** None of the tests use any libraries or special JavaScript features beyond the standard `==` operator. **Device platform and operating system** The benchmark results are reported for: * **Desktop**: Run on a Windows 10 desktop computer with Chrome 120 browser. * **Browser**: Used is Google Chrome version 120.0.0.0. * **Operating System**: Windows 10 (64-bit). **Other alternatives** If you want to compare performance of different comparison operators or functions, MeasureThat.net might not provide those options directly. However, you could try experimenting with different values and comparisons in your own benchmarking tests. For example, you could add more tests comparing different types of values, such as: * Comparing floating-point numbers (`const a = 1.0` and `const b = 1.0`) * Comparing arrays or objects (`const a = [1, 2, 3]` and `const b = [1, 2, 3]`) * Using regular expressions for comparison (`const a = "hello"` and `const b = "hello"`) Keep in mind that these additional tests would require modifying the benchmark definition and script preparation code to accommodate the new comparisons.
Related benchmarks:
parseInt(stringInt) vs +stringInt
Which equals operator (== vs ===) is faster (string vs int)?
String to number, parseInt, +, or * 1
Number.isInteger() vs typeof
Intl.Collator.compare() lowercase vs sensitivity vs localeCompare
Comments
Confirm delete:
Do you really want to delete benchmark?