Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Compare string equals performance without case diffs long strings
(version: 0)
Comparing performance of:
=== true vs locale compare true vs === false vs locale compare false
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.'; var b = 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.'; var c = 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H.'; var config = { sensitivity: 'base' };
Tests:
=== true
a === b
locale compare true
a.localeCompare(b, 'en', config);
=== false
a === c
locale compare false
a.localeCompare(c, 'en', config);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
=== true
locale compare true
=== false
locale compare false
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser/OS:
Chrome 119 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
=== true
18784930.0 Ops/sec
locale compare true
316374.9 Ops/sec
=== false
18740000.0 Ops/sec
locale compare false
262599.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll provide an explanation of the benchmark, options compared, pros and cons, and other considerations. **Benchmark Definition:** The benchmark compares three different approaches to checking if two strings are equal: 1. **Strict Equality (`a === b`)**: This method checks for exact equality between two strings using the `===` operator. 2. **Locale-Comparative (`a.localeCompare(b, 'en', config);`)**: This method uses the `localeCompare()` function to compare two strings in a case-insensitive manner, with a specific locale ('en') and sensitivity setting. **Individual Test Cases:** The benchmark consists of four test cases: 1. **Strict Equality (`a === b`)**: The test checks if two identical strings are equal using strict equality. 2. **Locale-Comparative (`a.localeCompare(b, 'en', config);`)**: The test checks if two identical strings are equal using locale-comparative with English locale and base sensitivity. 3. **Strict Equality (`a === c`)**: The test checks if two different strings are equal using strict equality (i.e., they should not be considered equal). 4. **Locale-Comparative (`a.localeCompare(c, 'en', config);`)**: The test checks if two different strings are equal using locale-comparative with English locale and base sensitivity. **Options Compared:** The benchmark compares the performance of: 1. Strict Equality (`a === b`) 2. Locale-Comparative (`a.localeCompare(b, 'en', config)`) **Pros and Cons:** 1. **Strict Equality (`a === b`)**: * Pros: + Simple to implement. + Fastest for identical strings. * Cons: + May return incorrect results for non-ASCII characters (depending on the locale). 2. **Locale-Comparative (`a.localeCompare(b, 'en', config);`)**: * Pros: + Handles non-ASCII characters correctly. + Provides a case-insensitive comparison with a specific locale. * Cons: + Slower than strict equality for identical strings. + Requires careful configuration (locale and sensitivity). **Other Considerations:** 1. **Performance:** The benchmark measures the execution speed of each test case, which is essential to determine the best approach depending on performance requirements. 2. **Accuracy:** The results of the locale-comparative method should be more accurate than strict equality for non-ASCII characters, but may introduce additional latency. 3. **Configuration:** The `config` object in the benchmark definition determines the sensitivity setting for locale-comparative comparisons. By comparing these two approaches, the benchmark provides a comprehensive view of the trade-offs between performance and accuracy in string comparison scenarios.
Related benchmarks:
IndexOf boolean vs Includes on string
Reduce w/ Lowercase vs. Magic Regex
Compare string equals performance with case long strings
Compare string equals performance with case long strings: with IntlCollator
Comments
Confirm delete:
Do you really want to delete benchmark?