var a = "John Doe"
var b = "john doe"
var c = "john smith"
var d = "joHn Smith"
var e = "JoHn SmiTh"
a.toLowerCase() == b.toLowerCase()
d.toLowerCase() == b.toLowerCase()
e.toLowerCase() == d.toLowerCase()
a.toLowerCase() == e.toLowerCase()
a.localeCompare(b, 'en', {'sensitivity': 'base'});
d.localeCompare(b, 'en', {'sensitivity': 'base'});
e.localeCompare(d, 'en', {'sensitivity': 'base'});
a.localeCompare(e, 'en', {'sensitivity': 'base'});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
TLC fail 1 | |
TLC pass 1 | |
TLC pass 2 | |
TLC fail 2 | |
LC fail 1 | |
LC pass 1 | |
LC pass 2 | |
LC fail 2 |
Test name | Executions per second |
---|---|
TLC fail 1 | 4713558.0 Ops/sec |
TLC pass 1 | 5397815.0 Ops/sec |
TLC pass 2 | 4529903.0 Ops/sec |
TLC fail 2 | 4506215.5 Ops/sec |
LC fail 1 | 192890.5 Ops/sec |
LC pass 1 | 192248.6 Ops/sec |
LC pass 2 | 192690.7 Ops/sec |
LC fail 2 | 189233.0 Ops/sec |
Overview
The provided JSON represents a benchmark test case for comparing case insensitivity in JavaScript string comparisons. The benchmark tests the performance of two approaches: using the toLowerCase()
method and using the localeCompare()
function with the sensitivity
option set to 'base'
.
Benchmark Definition
The benchmark definition is the script preparation code, which defines five strings:
a = "John Doe"
b = "john doe"
(case-insensitive comparison)c = "john smith"
(not used in this benchmark)d = "joHn Smith"
(case-insensitive comparison with extra 'H')e = "JoHn SmiTh"
(case-insensitive comparison)Test Cases
There are eight test cases, each defining a specific string comparison scenario:
a.toLowerCase() == b.toLowerCase()
- tests case insensitivity using the toLowerCase()
methodd.toLowerCase() == b.toLowerCase()
- tests case insensitivity using the toLowerCase()
method on a different stringe.toLowerCase() == d.toLowerCase()
- tests case insensitivity using the toLowerCase()
method on another stringa.localeCompare(b, 'en', {'sensitivity': 'base'})
- tests case insensitivity using the localeCompare()
function with sensitivity set to 'base'
5-8 are similar variations of test cases 1-3, but using different strings and locale settings.Options Compared
The two options being compared in this benchmark are:
toLowerCase()
method for case-insensitive comparisonslocaleCompare()
function with the sensitivity
option set to 'base'
Pros and Cons of Each Approach
toLowerCase()
Method:
Pros:
Cons:
LocaleCompare() Function with sensitivity set to 'base'
:
Pros:
Cons:
toLowerCase()
across older browsersOther Considerations
The benchmark also uses the sensitivity
option set to 'base'
, which affects how the localeCompare() function handles case-insensitive comparisons. This can have implications for how different locales handle character normalization and Unicode properties.
Library Used
None, as both toLowerCase()
and localeCompare()
are built-in JavaScript methods.
Overall, this benchmark aims to compare the performance of two approaches for case-insensitive string comparisons in JavaScript, highlighting the trade-offs between simplicity and precision in string comparison logic.