Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Intl.Collator.compare() lowercase vs sensitivity #4
(version: 0)
Comparing performance of:
lowercase vs sensitivity vs Intl.Collator vs localecompare
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = ['A', 'a', 'B', 'b', 'C', 'c', 'D', 'd']; var options = { sensitivity: 'accent' }; var collator1 = new Intl.Collator(undefined, options); var collator2 = new Intl.Collator();
Tests:
lowercase
arr.sort((a,b) => collator2.compare(a.toLowerCase(), b.toLowerCase()))
sensitivity
arr.sort(collator1.compare)
Intl.Collator
arr.sort((a,b) => Intl.Collator().compare(a.toLowerCase(), b.toLowerCase()))
localecompare
arr.sort((a,b) => a.toLowerCase().localeCompare(b.toLowerCase()))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
lowercase
sensitivity
Intl.Collator
localecompare
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/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lowercase
1839334.0 Ops/sec
sensitivity
2891037.0 Ops/sec
Intl.Collator
49208.3 Ops/sec
localecompare
5341389.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the provided benchmark. **Benchmark Overview** The benchmark measures the performance of three different approaches for comparing strings in JavaScript: `localeCompare`, using an `Intl.Collator` instance, and using an `Intl.Collator` instance with specific options. The test case compares the string comparison performance when sorting an array of uppercase and lowercase letters. **Script Preparation Code** The script preparation code creates two arrays (`arr`) containing uppercase and lowercase letters. It then creates three `Intl.Collator` instances: 1. `collator1`: An instance with specific options (`sensitivity: 'accent'`) 2. `collator2`: A default instance (no options specified) **Html Preparation Code** The HTML preparation code is empty. **Individual Test Cases** There are four test cases, each representing a different approach: 1. **lowercase**: Sorts the array using only lowercase letters. 2. **sensitivity**: Sorts the array using an `Intl.Collator` instance with specific options (`sensitivity: 'accent'`). 3. **Intl.Collator**: Sorts the array using a default `Intl.Collator` instance (no options specified). 4. **localecompare**: Sorts the array using the native `localeCompare` method. **Pros and Cons of Each Approach** Here's a brief overview of each approach, including their pros and cons: 1. **localeCompare**: * Pros: Widely supported, efficient, and easy to use. * Cons: May not work as expected for certain locale combinations or edge cases. 2. **Intl.Collator (default)**: * Pros: More accurate than `localeCompare` for some locales and uses accent sensitivity by default. * Cons: Requires an additional import and may have slower performance compared to `localeCompare`. 3. **Intl.Collator (sensitivity: 'accent')**: * Pros: Provides more precise comparison results, especially for accented characters. * Cons: May introduce additional overhead due to the specific options. **Libraries and Special JS Features** * `Intl.Collator`: A built-in JavaScript library that provides support for comparing strings in a locale-specific manner. It's used extensively in modern web development for tasks like sorting, filtering, and formatting dates and numbers. * Purpose: To provide a standardized way of comparing strings, taking into account the local language and regional settings. No special JS features are mentioned in this benchmark.
Related benchmarks:
Intl.Collator.compare() lowercase vs sensitivity
Intl.Collator.compare() lowercase vs sensitivity #2
Intl.Collator.compare() lowercase vs sensitivity #3
Intl.Collator.compare() lowercase vs sensitivity vs localeCompare
Comments
Confirm delete:
Do you really want to delete benchmark?