-
Notifications
You must be signed in to change notification settings - Fork 4
/
bench.js
72 lines (67 loc) · 2.05 KB
/
bench.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
/* eslint-disable no-unused-vars, no-unused-expressions, no-new */
const Benchmark = require('benchmark');
const moment = require('moment-timezone');
const dateFns = require('date-fns');
const {convert, format, parse, CivilTime, now, tz} = require('./');
const suite = new Benchmark.Suite();
let iunix = Date.now() / 1000;
let idate = new Date();
let idtfs = Date.now();
let icctz = convert(now(), tz('UTC'));
let immtz = moment().tz('America/New_York');
const intl = new Intl.DateTimeFormat('en-US', {timezone: 'America/New_York'});
suite
.add('Format (cctz)', () => {
format('%m/%d/%Y, %H:%M:%S %p', now(), tz('America/New_York'));
})
.add('Format (Date)', () => {
intl.format(Date.now());
})
.add('Format (date-fns)', () => {
dateFns.format(Date.now(), 'MM/DD/YYYY HH:mm:ss A');
})
.add('Format (moment)', () => {
moment.tz('America/New_York').format('M/D/YYYY, HH:mm:ss A');
})
.add('Parse (cctz)', () => {
parse('%Y-%m-%d %H:%M:%S %Ez', '2015-09-22 09:35:12+03:00');
})
.add('Parse (Date)', () => {
new Date('2015-09-22 09:35:12+03:00');
})
.add('Parse (date-fns)', () => {
dateFns.parse('2015-09-22 09:35:12+03:00');
})
.add('Parse (moment)', () => {
moment('2015-09-22 09:35:12+03:00').unix();
})
.add('Add hour (cctz)', () => {
icctz.hour += 1;
})
.add('Add hour (Date)', () => {
idate.setHours(idate.getHours() + 1);
})
.add('Add hour (date-fns)', () => {
dateFns.addHours(idtfs, 1);
})
.add('Add hour (moment)', () => {
immtz.add(1, 'h');
})
.add('Convert Ut->Time (cctz)', () => {
convert(now(), tz('America/New_York'));
})
.add('Convert Ut->Time (moment)', () => {
moment().tz('America/New_York');
})
.add('Convert Time->Ut (cctz)', () => {
convert(new CivilTime(2017, 2, 16, 14, 4, 0), tz('UTC'));
})
.add('Convert Time->Ut (moment)', () => {
moment([2017, 2, 16, 14, 4, 0]).unix();
})
.on('cycle', event => {
console.log(String(event.target));
})
.run({
async: true
});