-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
109 lines (93 loc) · 3.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import createSuite from './createSuite.js'
import { getPluralFormForCardinal } from 'plural-rules'
import { getPluralFormForCardinalByLocale } from 'fast-plural-rules'
import assert from 'assert'
function simpleCoded () {
assert(getPluralFormForCardinalByLocale('en', 1) === 0)
assert(getPluralFormForCardinalByLocale('en', 2) === 1)
assert(getPluralFormForCardinalByLocale('en', 5) === 1)
assert(getPluralFormForCardinalByLocale('en', 21) === 1)
}
function simpleParsed () {
assert(getPluralFormForCardinal('en', 1) === 'one')
assert(getPluralFormForCardinal('en', 2) === 'other')
assert(getPluralFormForCardinal('en', 5) === 'other')
assert(getPluralFormForCardinal('en', 21) === 'other')
}
function simpleNative () {
assert(new Intl.PluralRules('en').select(1) === 'one')
assert(new Intl.PluralRules('en').select(2) === 'other')
assert(new Intl.PluralRules('en').select(5) === 'other')
assert(new Intl.PluralRules('en').select(21) === 'other')
}
const en = new Intl.PluralRules('en')
function simpleNativeCached () {
assert(en.select(1) === 'one')
assert(en.select(2) === 'other')
assert(en.select(5) === 'other')
assert(en.select(21) === 'other')
}
function averageCoded () {
assert(getPluralFormForCardinalByLocale('cs', 1) === 0)
assert(getPluralFormForCardinalByLocale('cs', 2) === 1)
assert(getPluralFormForCardinalByLocale('cs', 5) === 2)
assert(getPluralFormForCardinalByLocale('cs', 21) === 2)
}
function averageParsed () {
assert(getPluralFormForCardinal('cs', 1) === 'one')
assert(getPluralFormForCardinal('cs', 2) === 'few')
assert(getPluralFormForCardinal('cs', 5) === 'other')
assert(getPluralFormForCardinal('cs', 21) === 'other')
}
function averageNative () {
assert(new Intl.PluralRules('cs').select(1) === 'one')
assert(new Intl.PluralRules('cs').select(2) === 'few')
assert(new Intl.PluralRules('cs').select(5) === 'other')
assert(new Intl.PluralRules('cs').select(21) === 'other')
}
const cs = new Intl.PluralRules('cs')
function averageNativeCached () {
assert(cs.select(1) === 'one')
assert(cs.select(2) === 'few')
assert(cs.select(5) === 'other')
assert(cs.select(21) === 'other')
}
function complicatedCoded () {
assert(getPluralFormForCardinalByLocale('ru', 1) === 0)
assert(getPluralFormForCardinalByLocale('ru', 2) === 1)
assert(getPluralFormForCardinalByLocale('ru', 5) === 2)
assert(getPluralFormForCardinalByLocale('ru', 21) === 0)
}
function complicatedParsed () {
assert(getPluralFormForCardinal('ru', 1) === 'one')
assert(getPluralFormForCardinal('ru', 2) === 'few')
assert(getPluralFormForCardinal('ru', 5) === 'many')
assert(getPluralFormForCardinal('ru', 21) === 'one')
}
function complicatedNative () {
assert(new Intl.PluralRules('ru').select(1) === 'one')
assert(new Intl.PluralRules('ru').select(2) === 'few')
assert(new Intl.PluralRules('ru').select(5) === 'many')
assert(new Intl.PluralRules('ru').select(21) === 'one')
}
const ru = new Intl.PluralRules('ru')
function complicatedNativeCached () {
assert(ru.select(1) === 'one')
assert(ru.select(2) === 'few')
assert(ru.select(5) === 'many')
assert(ru.select(21) === 'one')
}
createSuite('Getting a plural form...')
.add('using a simple coded rule', simpleCoded)
.add('using a simple parsed rule', simpleParsed)
.add('using a simple native rule', simpleNative)
.add('using a simple native cached rule', simpleNativeCached)
.add('using an average coded rule', averageCoded)
.add('using an average parsed rule', averageParsed)
.add('using an average native rule', averageNative)
.add('using an average native cached rule', averageNativeCached)
.add('using a complicated coded rule', complicatedCoded)
.add('using a complicated parsed rule', complicatedParsed)
.add('using a complicated native rule', complicatedNative)
.add('using a complicated native cached rule', complicatedNativeCached)
.start()