-
Notifications
You must be signed in to change notification settings - Fork 11
/
speed.js
34 lines (29 loc) · 1.12 KB
/
speed.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
const { DateTimeFormatter, SHORT_DATE } = require('./');
const date = new Date(2020, 05, 25);
const expected = '6/25/2020';
const runs = 10000;
// TODO: Add `SHORT_DATE` to observe keying works even with options provided
const dtf = new DateTimeFormatter('en-US', SHORT_DATE);
const dtfStamp = Date.now();
const dtfLaps = [];
for (let index = 0; index < runs; index++) {
const actual = dtf.formatDateTime(date);
dtfLaps.push(Date.now());
if (actual !== expected) {
throw new Error(`${actual} !== ${expected}`);
}
}
console.log(Date.now() - dtfStamp, 'total');
console.log('non-instant laps', dtfLaps.map((l, i) => l - (i === 0 ? dtfStamp : dtfLaps[i - 1])).filter(l => l));
const intl = new Intl.DateTimeFormat('en-US');
const intlStamp = Date.now();
const intlLaps = [];
for (let index = 0; index < runs; index++) {
const actual = intl.format(date);
intlLaps.push(Date.now());
if (actual !== expected) {
throw new Error(`${actual} !== ${expected}`);
}
}
console.log(Date.now() - intlStamp, 'total');
console.log('non-instant laps', intlLaps.map((l, i) => l - (i === 0 ? intlStamp : intlLaps[i - 1])).filter(l => l));