moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.05k stars 728 forks source link

Perf: Add benchmark for DateTime.local with zone #1574

Closed schleyfox closed 4 months ago

schleyfox commented 5 months ago

This is part of a series of PRs based on performance work we have done to improve a use-case involving parsing/formatting hundreds of thousands of dates where luxon was the bottleneck.

We found that time zone handling took up a lot of time. This adds a benchmark around this for DateTime.local (which uses quickDT and is the fastest path for creating DateTimes from date components. This also renames the existing DateTime.local benchmark to be DateTIme.now as it calls DateTime.now rather than local

DateTime.now x 3,076,386 ops/sec ±0.16% (98 runs sampled)
DateTime.fromObject with locale x 1,112,953 ops/sec ±0.08% (99 runs sampled)
DateTime.local with numbers x 844,898 ops/sec ±0.15% (100 runs sampled)
DateTime.local with numbers and zone x 50,913 ops/sec ±0.18% (97 runs sampled)
DateTime.fromISO x 329,144 ops/sec ±0.32% (98 runs sampled)
DateTime.fromSQL x 460,943 ops/sec ±0.16% (101 runs sampled)
DateTime.fromFormat x 60,666 ops/sec ±0.17% (100 runs sampled)
DateTime.fromFormat with zone x 26,687 ops/sec ±0.18% (100 runs sampled)
DateTime#setZone x 175,791 ops/sec ±0.29% (96 runs sampled)
DateTime#toFormat x 1,029,132 ops/sec ±0.15% (99 runs sampled)
DateTime#toFormat with macro x 450,668 ops/sec ±0.32% (95 runs sampled)
DateTime#toFormat with macro no cache x 12,197 ops/sec ±9.62% (80 runs sampled)
DateTime#add x 351,727 ops/sec ±3.49% (100 runs sampled)
DateTime#toISO x 6,169,310 ops/sec ±0.15% (100 runs sampled)
DateTime#toLocaleString x 517,180 ops/sec ±0.36% (98 runs sampled)
DateTime#toLocaleString in utc x 236,294 ops/sec ±0.34% (99 runs sampled)
DateTime#toRelativeCalendar x 14,076 ops/sec ±0.32% (95 runs sampled)
Fastest is DateTime#toISO
Info.months with existing locale x 52,033,486 ops/sec ±0.10% (100 runs sampled)
Info.months x 11,068,821 ops/sec ±0.47% (95 runs sampled)
Fastest is Info.months with existing locale
Info.monthsFormat with existing locale x 42,476,619 ops/sec ±1.00% (95 runs sampled)
Info.monthsFormat x 9,895,981 ops/sec ±0.26% (98 runs sampled)
Fastest is Info.monthsFormat with existing locale
Info.weekdays with existing locale x 43,636,745 ops/sec ±1.08% (99 runs sampled)
Info.weekdays x 12,718,724 ops/sec ±0.21% (98 runs sampled)
Fastest is Info.weekdays with existing locale
Info.weekdaysFormat with existing locale x 37,275,570 ops/sec ±0.67% (98 runs sampled)
Info.weekdaysFormat x 13,117,957 ops/sec ±0.62% (98 runs sampled)
Fastest is Info.weekdaysFormat with existing locale
linux-foundation-easycla[bot] commented 5 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.