let date;
date = new Date('2023-09-18T16:29:10.093Z');
date = new Date('2023-09-18');
date = new Date(1695054550093);
date = new Date();
date = new Date(2024, 1, 1);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
new Date(full string) | |
new Date(short string) | |
new Date(number) | |
new Date() | |
new Date(numbers) |
Test name | Executions per second |
---|---|
new Date(full string) | 5501832.0 Ops/sec |
new Date(short string) | 7502250.5 Ops/sec |
new Date(number) | 10610037.0 Ops/sec |
new Date() | 9117674.0 Ops/sec |
new Date(numbers) | 4751458.0 Ops/sec |
The benchmark named "Date constructor performance" aims to compare the performance of different types of inputs to the JavaScript Date
constructor. The benchmark is structured to measure how efficiently the JavaScript engine can parse various date formats and scenarios.
new Date(full string):
date = new Date('2023-09-18T16:29:10.093Z');
new Date(short string):
date = new Date('2023-09-18');
new Date(number):
date = new Date(1695054550093);
2023-09-18T16:29:10.093Z
.new Date():
date = new Date();
Date
object for the current date and time.new Date(numbers):
date = new Date(2024, 1, 1);
The results from the latest benchmark indicate the following ExecutionsPerSecond
for each test case:
new Date(number)
: 10,610,037new Date()
: 9,117,674new Date(short string)
: 7,502,250.5new Date(full string)
: 5,501,832new Date(numbers)
: 4,751,458new Date(number)
) significantly outperforms the others, confirming that using timestamps is generally the most efficient for date creation.full string
and short string
), parsing date strings can be computationally more expensive.Date
usage. However, they also handle edge cases effectively, which can be helpful in robust applications.Date
object.In summary, this benchmark provides crucial insights into the performance implications of various methods for creating Date
objects in JavaScript, helping developers choose the right approach based on their specific needs.