Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date.now() vs new Date() vs performance.now()
(version: 0)
Comparing performance of:
Date.now() vs new Date(); vs performance.now()
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var timestamp = null;
Tests:
Date.now()
timestamp = Date.now();
new Date();
timestamp = new Date();
performance.now()
timestamp = performance.now()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Date.now()
new Date();
performance.now()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Date.now()
28529338.0 Ops/sec
new Date();
24682098.0 Ops/sec
performance.now()
11619598.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **What is being tested?** The benchmark is designed to compare the performance of three different methods to get the current time: 1. `Date.now()` 2. `new Date()` 3. `performance.now()` These methods are used to measure the passage of time, but they have different characteristics that affect their performance. **Options being compared** The options being compared are: * `Date.now()`: This method returns the number of milliseconds since the Unix Epoch (January 1, 1970, 00:00:00 UTC). It's a simple and straightforward way to get the current time. * `new Date()`: This method creates a new `Date` object representing the current date and time. While it may seem similar to `Date.now()`, creating a new `Date` object can be more expensive due to object creation overhead. * `performance.now()`: This method returns the number of milliseconds since the performance counter was started. It's designed specifically for measuring elapsed time in high-performance applications. **Pros and Cons** Here are some pros and cons of each approach: * `Date.now()`: + Pros: Simple, fast, and widely supported. + Cons: May not be suitable for very large intervals (e.g., measuring the passage of hours or days), as it uses a fixed epoch value that may drift over time. * `new Date()`: + Pros: Can provide more precision than `Date.now()`, as it creates a new object with a specific timestamp. + Cons: More expensive due to object creation overhead, and may not be suitable for high-performance applications where speed is critical. * `performance.now()`: + Pros: Specifically designed for measuring elapsed time in high-performance applications, providing the best possible accuracy and speed. + Cons: May not be supported in older browsers or environments that don't have a performance counter. **Library** None of these methods rely on any external libraries. They are all built-in JavaScript functions. **Special JS feature or syntax** There's no special JavaScript feature or syntax being used here, just standard JavaScript function calls. **Other alternatives** If you need more precise timing or want to measure time intervals in a specific unit (e.g., milliseconds, seconds), you may consider using other libraries like `ms` or `moment.js`. However, for simple cases where you just need to measure the passage of time, these built-in methods should be sufficient. Keep in mind that while these methods are suitable for most use cases, there may be specific requirements for high-performance applications or situations where accuracy is critical. In such cases, more specialized libraries or frameworks might be necessary.
Related benchmarks:
Date.now() vs new Date().getTime()
Date.now() vs new Date()
Date.now() vs new performance.now()
Date.now() - Date.now() vs new Date() - new Date()
Comments
Confirm delete:
Do you really want to delete benchmark?