Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date.now() - Date.now() vs new Date() - new Date()
(version: 0)
Comparing performance of:
Date.now() vs new Date().getTime();
Created:
3 years ago
by:
Guest
Go to the latest result
Script Preparation code:
var timedif = null;
Tests:
Date.now()
timedif = Date.now() - Date.now();
new Date().getTime();
timedif = new Date() - new Date();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Date.now()
new Date().getTime();
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Browser/OS:
Firefox 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Date.now()
5.5M/s
new Date().getTime();
2.4M/s
View exact numbers
Test name
Executions per second
✓
Date.now()
5,486,806 Ops/sec
new Date().getTime();
2,385,764 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark on MeasureThat.net compares the performance of two methods for calculating the time difference in JavaScript: * **`Date.now()`**: This method returns the number of milliseconds that have elapsed since the Unix epoch (January 1, 1970, 00:00:00 UTC). * **`new Date().getTime()`**: This creates a new `Date` object and then uses its `.getTime()` method to get the number of milliseconds since the Unix epoch. **Breakdown:** The benchmark code essentially performs these actions in both test cases: 1. **Creates a variable:** `timedif = null;` is used to store the calculated time difference. 2. **Performs the calculation:** * Test case 1: `timedif = Date.now() - Date.now();` This calculates the difference between the current time and itself, always resulting in 0. * Test case 2: `timedif = new Date() - new Date();` This creates two new `Date` objects and subtracts their timestamps. **Pros & Cons:** * **`Date.now()`**: * **Pros**: This method is very efficient as it's a built-in function optimized for performance. It directly returns the milliseconds since the epoch without any additional object creation. * **Cons**: Can be limited if you need more precise time information than milliseconds or require specific date and time formatting. * **`new Date().getTime()`**: * **Pros**: Offers more flexibility as it allows access to other `Date` object methods for manipulating and formatting the timestamp (e.g., getting year, month, day, etc.). * **Cons**: Generally slower than `Date.now()`, as it involves creating a new `Date` object and then calling `.getTime()` **Other Considerations:** This benchmark highlights that `Date.now()` is significantly faster for simple time difference calculations in JavaScript. Let me know if you have any more questions about this or other benchmarks!
Related benchmarks
Date.now() vs new Date().getTime()
new Date().getTime() vs Date.now()
Date.now() vs new Date()
Comments
Confirm delete:
Do you really want to delete benchmark?