Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Intl.Collator.compare() lowercase vs sensitivity #3
(version: 0)
Comparing performance of:
lowercase vs sensitivity vs Intl.Collator
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()))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lowercase
sensitivity
Intl.Collator
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
1774996.5 Ops/sec
sensitivity
2859483.0 Ops/sec
Intl.Collator
49068.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Overview** The benchmark is designed to compare three different approaches for sorting an array of strings using the `Intl.Collator` API: 1. Using a custom collator with sensitivity set to `'accent'` 2. Sorting without any custom collator 3. Using a new, global `Intl.Collator()` instance **Library: Intl.Collator** The `Intl.Collator` API is a part of the Internationalization API in JavaScript, which provides support for comparing strings based on various locale-specific rules. The primary purpose of `Intl.Collator` is to sort strings in a way that takes into account the nuances of human language, such as accents and diacritical marks. **Options compared** The benchmark compares three different options: 1. **Custom collator with sensitivity set to `'accent'`**: This option creates a new `Intl.Collator` instance with custom settings (sensitivity) that prioritize accent-based sorting. This allows for more precise control over the comparison rules. 2. **Sorting without any custom collator**: This option relies on the default comparison behavior of JavaScript's built-in string sorting algorithm, which may not take into account all locale-specific rules. 3. **New, global `Intl.Collator()` instance**: This option uses a new, shared instance of `Intl.Collator` for all comparisons. Since this instance is reused, its settings and locale information are preserved between runs. **Pros and Cons** Here's a brief overview of the pros and cons of each approach: 1. **Custom collator with sensitivity set to `'accent'`**: * Pros: More precise control over comparison rules, takes into account accents and diacritical marks. * Cons: Requires more code and setup, may have performance implications due to custom configuration. 2. **Sorting without any custom collator**: * Pros: Simple and lightweight, relies on built-in string sorting algorithm. * Cons: May not take into account all locale-specific rules, can lead to inconsistent results. 3. **New, global `Intl.Collator()` instance**: * Pros: Convenient and easy to use, reuses the same instance for all comparisons. * Cons: Preserves settings and locale information between runs, which may not be desirable in some cases. **Special JS feature or syntax** The benchmark uses a special JavaScript feature called **arrow functions**, which are used to define small, one-line functions. This syntax is introduced in ECMAScript 2015 (ES6) and provides a concise way to create functions without the need for `function` keywords. Now that we've explained what's being tested, let's discuss alternative approaches: * Other alternatives could include using different comparison algorithms or data structures, such as sorting arrays using a library like Lodash or implementing a custom sorting algorithm. * Alternatively, the benchmark could focus on testing specific aspects of the `Intl.Collator` API, such as its handling of Unicode characters or support for multiple locales.
Related benchmarks:
Intl.Collator.compare() lowercase vs sensitivity
Intl.Collator.compare() lowercase vs sensitivity #2
Intl.Collator.compare() lowercase vs sensitivity #4
Intl.Collator.compare() lowercase vs sensitivity vs localeCompare
Comments
Confirm delete:
Do you really want to delete benchmark?