Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date.toLocaleDateString vs dayjs vs luxon vs custom
(version: 0)
Comparing performance of:
Date.toLocaleDateString vs luxon vs dayjs vs custom
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src=" https://cdn.jsdelivr.net/npm/dayjs@1.11.10/dayjs.min.js "></script> <script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.10/locale/ru.js"></script> <script src=" https://cdn.jsdelivr.net/npm/luxon@3.4.4/build/global/luxon.min.js "></script>
Script Preparation code:
var DATE_STR = "2024-01-01T01:01:01.001Z"; var MONTH_NAMES = [ "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря" ]; function formatDateRead(date) { return `${date.getDate().toString()} ${MONTH_NAMES[date.getMonth()]} ${date.getFullYear()}`; }
Tests:
Date.toLocaleDateString
new Date(DATE_STR).toLocaleDateString('ru-RU', { day: 'numeric', month: 'long', year: 'numeric', }).slice(0, -3);
luxon
luxon.DateTime.fromISO(DATE_STR).setLocale("ru").toFormat('d MMMM yyyy');
dayjs
dayjs(DATE_STR).locale('ru').format('D MMMM YYYY');
custom
formatDateRead(new Date(DATE_STR));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Date.toLocaleDateString
luxon
dayjs
custom
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/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Date.toLocaleDateString
4732.9 Ops/sec
luxon
2341.4 Ops/sec
dayjs
112125.9 Ops/sec
custom
771019.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided JSON represents a benchmarking test case that compares the performance of four different approaches to format dates in Russian (ru-RU) locale: 1. `Date.toLocaleDateString()` 2. `luxon.DateTime.fromISO()` with `setLocale()` and `toFormat()` methods 3. `dayjs()` with `locale()` and `format()` methods 4. A custom implementation using a separate function `formatDateRead()` **Options compared** The benchmark tests the following options: * Using the built-in JavaScript `Date` object (`Date.toLocaleDateString()`) * Using the `luxon` library, which is a modern date and time API for JavaScript * Using the `dayjs` library, which is a lightweight alternative to moment.js for date and time calculations * A custom implementation using a separate function (`formatDateRead()`) **Pros and Cons of each approach** 1. **Built-in JavaScript `Date` object**: * Pros: Widely supported, easy to use, and part of the JavaScript standard library. * Cons: May not be as efficient or feature-rich as other libraries. 2. **luxon library**: * Pros: Modern API, high performance, and features like timezone handling. * Cons: Requires additional setup (installing the library) and may have a steeper learning curve due to its unique API. 3. **dayjs library**: * Pros: Lightweight, easy to use, and has a simple API. * Cons: May not be as performant as luxon or custom implementations, and some features might be limited compared to other libraries. 4. **Custom implementation (`formatDateRead()`)**: * Pros: Can be optimized for specific use cases or performance requirements. * Cons: Requires more code and maintenance effort, and may not benefit from the same level of optimization as a well-written library. **Library explanations** * `luxon`: A modern date and time API for JavaScript that provides high-performance and flexibility. It is designed to replace existing libraries like moment.js. * `dayjs`: A lightweight alternative to moment.js for date and time calculations. It has a simple API and is optimized for performance. **Special JS feature or syntax** The benchmark uses the `toLocaleDateString()` method, which is a part of the JavaScript standard library, but its usage might require some attention to locale settings and formatting options. **Benchmark preparation code** The provided HTML code includes three external libraries: * `dayjs@1.11.10/dayjs.min.js`: The main dayjs library. * `dayjs@1.11.10/locale/ru.js`: A locale-specific module for the dayjs library, which provides formatting options specific to the Russian language (ru-RU). * `luxon@3.4.4/build/global/luxon.min.js`: The main luxon library. The custom implementation (`formatDateRead()`) does not require any external libraries. **Alternatives** Other alternatives for date and time calculations in JavaScript include: * Moment.js: A widely used, feature-rich library for date and time calculations. * Date-fns: A lightweight, modern alternative to moment.js with a simple API. * Firebase Timestamps: A built-in timestamp library provided by Google Firebase. Keep in mind that each of these alternatives has its own strengths and weaknesses, and the choice ultimately depends on the specific requirements and use cases.
Related benchmarks:
toLocalDateString vs Array index
Moment format against Date
toLocaleDateString_perf
Avith test date format from string
Luxon vs Native ISO date parsing
Comments
Confirm delete:
Do you really want to delete benchmark?