var a = 'aBcD eFgH iJkLmN'
var b = 'AbCd eFgH iJkLmN'
var c = 'aBcD eFgH iJkLmNx'
var d = 'aBcD eFgH iJkLmn'
var enCollator = new Intl.Collator('en', { sensitivity: 'accent' });
a.toLowerCase() === b.toLowerCase()
enCollator.compare(a, b) === 0
a.toUpperCase() === b.toUpperCase()
a === b
a.toLowerCase() === c.toLowerCase()
a.toLowerCase() === d.toLowerCase()
!!(a && b && a.toLowerCase() === b.toLowerCase())
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
LowerCase compare a&b | |
Collator compare | |
UpperCase compare | |
Sensitive compare | |
Lower a & c | |
Lower a & d | |
Undefined test & lower a&b |
Test name | Executions per second |
---|---|
LowerCase compare a&b | 8036329.5 Ops/sec |
Collator compare | 3277209.8 Ops/sec |
UpperCase compare | 7423636.0 Ops/sec |
Sensitive compare | 9373343.0 Ops/sec |
Lower a & c | 8028903.0 Ops/sec |
Lower a & d | 8074987.0 Ops/sec |
Undefined test & lower a&b | 4329966.5 Ops/sec |
Overview of the Benchmark
The provided JSON represents a benchmarking test for comparing strings in JavaScript, with various sensitivity levels and Unicode character cases. The test uses a set of predefined strings (a
, b
, c
, and d
) to measure the performance of different string comparison approaches.
Comparison Options
There are four main comparison options:
toLowerCase()
method.toUpperCase()
method.Intl.Collator
) to compare two strings based on their Unicode character case and sensitivity.Pros and Cons of Each Approach
Library and Syntax
The test uses the ICU Collator library (Intl.Collator
) to perform the collator comparison. This library is part of the JavaScript standard library and provides a way to normalize and compare strings based on their Unicode character case and sensitivity.
No special JavaScript syntax or features are used in this benchmark, apart from using template literals for string concatenation.
Other Alternatives
For alternative approaches, consider:
^abc$
for exact matches)String.prototype.localeCompare()
or punycode