()
| 6 | // due to 700+ locales being auto-loaded and slow locale matching |
| 7 | |
| 8 | async function run() { |
| 9 | const bench = new Bench({time: 1000}) |
| 10 | |
| 11 | bench |
| 12 | // Test instantiation with exact locale match (should be fast with optimization) |
| 13 | .add('new DurationFormat("en")', () => { |
| 14 | new DurationFormat('en') |
| 15 | }) |
| 16 | |
| 17 | // Test with common locales |
| 18 | .add('new DurationFormat("en-US")', () => { |
| 19 | new DurationFormat('en-US') |
| 20 | }) |
| 21 | |
| 22 | .add('new DurationFormat("ja")', () => { |
| 23 | new DurationFormat('ja') |
| 24 | }) |
| 25 | |
| 26 | .add('new DurationFormat("fr")', () => { |
| 27 | new DurationFormat('fr') |
| 28 | }) |
| 29 | |
| 30 | // Test fallback path with multi-level subtag removal |
| 31 | .add('new DurationFormat("zh-Hans-CN") [fallback: zh-Hans]', () => { |
| 32 | new DurationFormat('zh-Hans-CN') |
| 33 | }) |
| 34 | |
| 35 | .add('new DurationFormat("en-US-x-custom") [fallback: en-US → en]', () => { |
| 36 | new DurationFormat('en-US-x-custom') |
| 37 | }) |
| 38 | |
| 39 | // Test with fuzzy matching (locale not in available set) |
| 40 | .add('new DurationFormat("en-XZ") [fuzzy match]', () => { |
| 41 | new DurationFormat('en-XZ') |
| 42 | }) |
| 43 | |
| 44 | // Test with options (still needs locale resolution) |
| 45 | .add('new DurationFormat("en", {style: "digital"})', () => { |
| 46 | new DurationFormat('en', {style: 'digital'}) |
| 47 | }) |
| 48 | |
| 49 | // Test with multiple requested locales |
| 50 | .add('new DurationFormat(["fr", "en"])', () => { |
| 51 | new DurationFormat(['fr', 'en']) |
| 52 | }) |
| 53 | |
| 54 | // Test with lookup matcher (different algorithm) |
| 55 | .add('new DurationFormat("en", {localeMatcher: "lookup"})', () => { |
| 56 | new DurationFormat('en', {localeMatcher: 'lookup'}) |
| 57 | }) |
| 58 | |
| 59 | // Test with best fit matcher (default) |
| 60 | .add('new DurationFormat("en", {localeMatcher: "best fit"})', () => { |
| 61 | new DurationFormat('en', {localeMatcher: 'best fit'}) |
| 62 | }) |
| 63 | |
| 64 | await bench.run() |
| 65 |
no test coverage detected