Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS Date libraries 2 fixed
(version: 0)
Comparing performance of:
luxon vs dayjs vs js-joda
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/luxon@1.26.0/build/global/luxon.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@js-joda/core@5.6.1/dist/js-joda.min.js"></script> <script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script> <script src="https://unpkg.com/dayjs@1.8.21/plugin/isBetween.js"></script> <script src="https://wzrd.in/standalone/dateformat@latest"></script>
Script Preparation code:
dayjs.extend(window.dayjs_plugin_isBetween) window.__date__ = new Date('2000-01-06T03:24:11'); window.__another_date__ = new Date('2000-01-30T03:24:11'); window.__another_month__ = new Date('2000-02-01T00:00:00'); window.__another_year__ = new Date('1999-01-06T03:24:11'); window.__saturday__ = new Date('2021-05-01T03:24:11'); window.__sunday__ = new Date('2021-05-02T03:24:11'); window._expected_string = '2000/01/06'; window._expected_start = '2000/01/01'; window._expected_end = '2000/01/31'; window._expected_day_of_week = 1;
Tests:
luxon
var actual = luxon.DateTime.fromJSDate(__date__); console.assert(actual.toFormat('yyyy/MM/dd') === _expected_string); var start = actual.startOf('month'); console.assert(start.toFormat('yyyy/MM/dd') === _expected_start); var end = actual.endOf('month'); console.assert(end.toFormat('yyyy/MM/dd') === _expected_end); var i = luxon.Interval.fromDateTimes(start, end); var isBefore = luxon.DateTime.fromJSDate(__another_date__) < end; console.assert(isBefore === true); var isBetween = i.contains(actual); console.assert(isBetween === true); var isInclusive = i.contains(start); console.assert(isInclusive === true); console.assert(luxon.DateTime.fromJSDate(__saturday__).weekday === 6); console.assert(start.hasSame(end, 'month') === true); console.assert(luxon.DateTime.fromJSDate(__another_month__).hasSame(end, 'month') === false); console.assert(luxon.DateTime.fromJSDate(__another_year__).hasSame(actual, 'month') === false); console.assert(luxon.DateTime.fromJSDate(__sunday__).daysInMonth === 31);
dayjs
var actual = dayjs(__date__); console.assert(actual.format('YYYY/MM/DD') === _expected_string); var start = actual.startOf('month'); console.assert(start.format('YYYY/MM/DD') === _expected_start); var end = actual.endOf('month'); console.assert(end.format('YYYY/MM/DD') === _expected_end); var isBetween = actual.isBetween(start, end); console.assert(isBetween === true); var isInclusive = start.isBetween(start, end, 'day', '[]'); console.assert(isInclusive === true); console.assert(dayjs(__saturday__).day() === 6); console.assert(start.isSame(end, 'month') === true); console.assert(dayjs(__another_month__).isSame(end, 'month') === false); console.assert(dayjs(__another_year__).isSame(actual, 'month') === false); console.assert(dayjs(__sunday__).daysInMonth() === 31);
js-joda
var actual = JSJoda.LocalDate.from(JSJoda.nativeJs(__date__)); console.assert(actual.format(JSJoda.DateTimeFormatter.ofPattern('yyyy/MM/dd')) === _expected_string); var start = actual.with(JSJoda.TemporalAdjusters.firstDayOfMonth()); console.assert(start.format(JSJoda.DateTimeFormatter.ofPattern('yyyy/MM/dd')) === _expected_start); var end = actual.with(JSJoda.TemporalAdjusters.lastDayOfMonth()); console.assert(end.format(JSJoda.DateTimeFormatter.ofPattern('yyyy/MM/dd')) === _expected_end); var isBetween = actual.compareTo(start) >= 0 && actual.compareTo(end) <= 0; console.assert(isBetween === true); var isInclusive = start.compareTo(start) >= 0 && start.compareTo(end) <= 0; console.assert(isInclusive === true); console.assert(JSJoda.LocalDate.from(JSJoda.nativeJs(__saturday__)).dayOfWeek() === JSJoda.DayOfWeek.SATURDAY); console.assert(start.withDayOfMonth(1).equals(end.withDayOfMonth(1))); console.assert(JSJoda.LocalDate.from(JSJoda.nativeJs(__another_month__)).withDayOfMonth(1).equals(end.withDayOfMonth(1)) === false); console.assert(JSJoda.LocalDate.from(JSJoda.nativeJs(__another_year__)).withDayOfMonth(1).equals(actual.withDayOfMonth(1)) === false); console.assert(JSJoda.LocalDate.from(JSJoda.nativeJs(__sunday__)).lengthOfMonth() === 31);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
luxon
dayjs
js-joda
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what is being tested, compared options, pros and cons of each approach, library usage, special JavaScript features, and other considerations. **Benchmark Overview** The benchmark compares the performance of three JavaScript date libraries: Luxon, Day.js, and JSJoda. Each library has its own strengths and weaknesses, which are highlighted in this benchmark. **Tested Options** 1. **Luxon**: Used for parsing dates from a string, determining the start and end of a month, creating intervals between dates, checking if a date is within an interval, and determining the day of the week. 2. **Day.js**: Used for formatting dates, determining the start and end of a month, checking if a date is within an interval, and determining the day of the week. 3. **JSJoda**: Used for parsing dates from a string, determining the start and end of a month, creating intervals between dates, checking if a date is within an interval, and determining the day of the week. **Comparison** The benchmark compares the performance of each library by executing the same test cases multiple times (specifically, 104414.515625 times for Luxon, 30156.06640625 times for Day.js, and 21717.28125 times for JSJoda). The results are then reported as executions per second. **Pros and Cons of Each Library** 1. **Luxon**: Pros: * Fast performance * Simple API * Wide range of features (e.g., date parsing, interval creation) Cons: * May require more code to accomplish tasks compared to other libraries 2. **Day.js**: Pros: * Easy-to-use API * Simple formatting options Cons: * Performance may be slower than Luxon and JSJoda for complex date operations 3. **JSJoda**: Pros: * Robust feature set (e.g., interval creation, day of the week calculation) Cons: * May have a steeper learning curve due to its complexity **Library Usage** Each library has its own way of handling dates and time calculations. 1. **Luxon**: Uses a functional programming style with a strong focus on date parsing and formatting. 2. **Day.js**: Employs a simple, intuitive API for formatting dates and determining the start and end of a month. 3. **JSJoda**: Utilizes a more traditional object-oriented approach with a focus on creating a robust feature set. **Special JavaScript Features** None of the libraries rely heavily on special JavaScript features like ES6+ syntax or advanced functional programming concepts. **Other Considerations** * The benchmark is executed on a Windows desktop environment using Chrome 118 as the browser. * The results may not be representative of other operating systems, browsers, or devices. * It's worth noting that the performance differences between the libraries are relatively small, and the choice of library ultimately depends on specific requirements and personal preference.
Related benchmarks:
JS Date libraries 2
Date libraries benchmark JS 1
Dayjs Date-fns format comparison 6
JS Date libraries 2023.0
Comments
Confirm delete:
Do you really want to delete benchmark?