<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 = dayjs(new Date("2020-02-19T00:51:53.623839+00:00"));
window.datefns.startOfWeek(window.ds.toDate());
dayjs().startOf("week")
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Date-fns | |
Dayjs |
Test name | Executions per second |
---|---|
Date-fns | 3029425.8 Ops/sec |
Dayjs | 3428124.0 Ops/sec |
Let's break down the benchmark and explain what's being tested.
Overview
The benchmark is designed to compare the performance of two libraries: Dayjs and Date-fns, specifically in terms of formatting dates. The test involves generating a date string using each library and then comparing it with another function from the same library (Date-fns).
Options Compared
There are two options being compared:
Pros and Cons
Library Descriptions
Special JS Features or Syntax
The test case uses some special features in the browsers' userAgent strings to identify the browser and device type:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15
indicates that this is a Safari 16 browser running on a Mac with macOS 10.15.7.Other Alternatives
For date manipulation tasks in JavaScript, other alternatives to Dayjs and Date-fns include:
Benchmark Preparation Code
The provided script preparation code includes two scripts:
dayjs.min.js
: The Dayjs library.datefns.js
: The Date-fns library.These libraries are loaded into the browser using their respective script tags.
Individual Test Cases
There are two individual test cases in this benchmark:
Both test cases use the startOfWeek
function, which returns the first day of the week for a given date.
I hope this explanation helps you understand what's being tested in this benchmark!