<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script src="https://igor.moomers.org/random/datefns.js"></script>
window.ds = "2023-02-19T00:51:53.623839+00:00";
window.datefns.parseISO(window.ds);
window.datefns.format(new Date(), "mm-dd-yyyy");
dayjs(window.ds)
dayjs().format("MM-DD-YYYY")
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
date-fns | |
day.js |
Test name | Executions per second |
---|---|
date-fns | 197334.9 Ops/sec |
day.js | 258759.6 Ops/sec |
Let's break down what's happening in this benchmark.
Overview
The website MeasureThat.net
is used to create and run JavaScript microbenchmarks. A microbenchmark is a small test that measures the performance of a specific piece of code or library.
In this case, we have two individual test cases:
Options being compared
The options being compared are two different libraries for working with dates in JavaScript:
datefns
: A popular date and time utility library developed by Dateutil (https://github.com/date-io/date-fns).day.js
: A lightweight, easy-to-use library for working with dates and times (https://igor.moomers.org/random/datefns.js).Pros and cons of each approach
datefns
:day.js
:Library usage
Both libraries are used in the benchmark:
datefns
is imported via a script tag in the HTML preparation code: <script src="https://igor.moomers.org/random/datefns.js"></script>
day.js
is imported via another script tag in the HTML preparation code: <script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
Special JS feature or syntax
There are no special JS features or syntaxes being used in this benchmark, other than possibly using ES6 imports (not explicitly shown).
Other alternatives
If you're looking for alternative libraries for date and time manipulation in JavaScript, here are a few:
moment.js
: A popular library for working with dates and times that's been around since 2011.luxon
: Another lightweight library for working with dates and times that's gaining popularity.Keep in mind that each library has its strengths and weaknesses, so it's essential to choose the one that best fits your specific use case.