Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
dayjs vs luxon vs js-joda vs date-fns (calculating)
(version: 5)
Comparing performance of:
Dayjs vs luxon vs js-joda vs date-fns
Created:
2 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.9/dayjs.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@3.4.3/build/global/luxon.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@js-joda/core@5.5.3/dist/js-joda.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.9.0/date_fns.min.js"></script>
Script Preparation code:
var dayjsDate1 = dayjs('2022-09-01T00:00:00+09:00'); var dayjsDate2 = dayjs('2023-09-01T00:00:00+09:00'); var luxonDate1 = luxon.DateTime.fromISO("2022-09-01T00:00:00+09:00"); var luxonDate2 = luxon.DateTime.fromISO("2023-09-01T00:00:00+09:00"); var jsJodaDate1 = JSJoda.ZonedDateTime.parse('2022-09-01T00:00:00+09:00', JSJoda.DateTimeFormatter.ISO_OFFSET_DATE_TIME); var jsJodaDate2 = JSJoda.ZonedDateTime.parse('2023-09-01T00:00:00+09:00', JSJoda.DateTimeFormatter.ISO_OFFSET_DATE_TIME); var date1 = new Date('2022-09-01T00:00:00+09:00'); var date2 = new Date('2023-09-01T00:00:00+09:00');
Tests:
Dayjs
dayjsDate2.diff(dayjsDate1, 'month');
luxon
luxonDate2.diff(luxonDate1, 'months');
js-joda
jsJodaDate1.until(jsJodaDate2, JSJoda.ChronoUnit.MONTHS);
date-fns
dateFns.differenceInMonths(date2, date1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Dayjs
luxon
js-joda
date-fns
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Dayjs
48131.8 Ops/sec
luxon
144256.9 Ops/sec
js-joda
1896737.1 Ops/sec
date-fns
478867.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Overview** The provided benchmark compares four date manipulation libraries: dayjs, luxon, js-joda, and date-fns. The benchmark focuses on calculating the difference between two dates in different units (months). **Library Description** 1. **Dayjs**: A popular library for working with dates and times in JavaScript. It provides a simple and intuitive API for various date-related tasks. 2. **Luxon**: A modern JavaScript date and time library that offers a robust feature set, including support for various date formats, time zones, and cultural calendars. 3. **Js-joda**: A Java-based library adapted to JavaScript, providing a comprehensive set of features for working with dates and times, including zone-aware calculations. 4. **Date-fns**: A small and lightweight library that provides a simple API for common date and time operations. **Comparison Options** The benchmark compares the performance of each library when calculating the difference between two dates in different units: * Dayjs: `diff` function with `'month'` unit * Luxon: `diff` function with `'months'` unit * Js-joda: `until` function with `JSJoda.ChronoUnit.MONTHS` value * Date-fns: `differenceInMonths` function **Pros and Cons** Here's a brief overview of the pros and cons of each library: 1. **Dayjs**: * Pros: Simple API, fast execution, widely supported. * Cons: Limited feature set compared to other libraries. 2. **Luxon**: * Pros: Robust feature set, flexible date formats, time zones support. * Cons: Steeper learning curve due to its comprehensive nature. 3. **Js-joda**: * Pros: Comprehensive feature set, zone-aware calculations, Java-like API. * Cons: Adapting a Java-based library to JavaScript can be challenging. 4. **Date-fns**: * Pros: Lightweight, simple API, fast execution. * Cons: Limited feature set compared to other libraries. **Special JS Feature/Syntax** None of the libraries in this benchmark use any special JavaScript features or syntax beyond standard ECMAScript 2020 syntax. **Benchmark Results** The latest benchmark results show that: 1. Js-joda has the highest executions per second (1896737.125). 2. Date-fns is close behind with a relatively high execution rate (48131.78125). 3. Luxon and Dayjs have lower execution rates, but still offer competitive performance. **Other Alternatives** If you're looking for alternative libraries to these four options, consider: 1. **Moment.js**: A popular library for working with dates and times in JavaScript. 2. **Date picker libraries**: Such as DateRangePicker or FullCalendar, which provide more comprehensive date management features. 3. **Custom implementations**: Using standard ECMAScript 2020 functions like `Date`, `getTime()`. Keep in mind that the choice of library depends on your specific project requirements and personal preferences.
Related benchmarks:
luxon.fromSeconds(seconds) vs Date(seconds * 1000)
dayjs vs luxon vs js-joda vs date-fns (formatting)
dayjs vs luxon vs js-joda vs date-fns (comparing)
dayjs vs luxon vs js-joda vs date-fns (manipulating)
Comments
Confirm delete:
Do you really want to delete benchmark?