<script src="https://unpkg.com/dayjs@1.11.9/dayjs.min.js"></script>
<script src="https://igor.moomers.org/random/datefns.js"></script>
window.ds = "2020-02-19T00:51:53.623839+00:00";
window.datefns.format(window.datefns.parseISO(window.ds), "yyyy-mm-dd")
dayjs(ds).format("YYYY-MM-DD")
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Date-fns | |
Dayjs |
Test name | Executions per second |
---|---|
Date-fns | 401307.4 Ops/sec |
Dayjs | 432142.1 Ops/sec |
I'll break down the provided benchmark JSON and explain what's being tested, compared, and considered.
Benchmark Overview
The benchmark compares the performance of two date formatting libraries: Dayjs (formerly known as Moment.js) and Date-fns. The test case focuses on parsing an ISO-formatted string and then formatting it into a specific format using each library.
Library Description
Options Compared
The benchmark compares two different approaches to formatting the parsed ISO-formatted string:
format()
method to format the parsed date into a specific format ("YYYY-MM-DD"
).format()
function from Date-fns to achieve the same result.Pros and Cons
Special JS Feature or Syntax
None mentioned in this specific benchmark. However, it's worth noting that both libraries have their own ways of handling edge cases and formatting options, which can affect performance.
Other Alternatives
If you're considering using a different date formatting library, here are some alternatives:
Benchmark Preparation Code
The provided Html Preparation Code
includes two script tags:
dayjs.min.js
).datefns.js
file from a third-party repository, which provides the Date-fns implementation for this benchmark.The Script Preparation Code
sets up a variable ds
with a sample ISO-formatted string.
Individual Test Cases
Each test case focuses on formatting a single date using either Dayjs or Date-fns. The specific options used in each test case are:
window.datefns.format(window.datefns.parseISO(window.ds), "yyyy-mm-dd")
dayjs(ds).format("YYYY-MM-DD")
These test cases aim to compare the performance of these two libraries in formatting dates using a specific format.