Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
new Date().getTime() vs Date.now()
(version: 0)
Comparing performance of:
new Date().getTime() vs Date.now()
Created:
5 years ago
by:
Registered User
Jump to the latest result
Tests:
new Date().getTime()
var x = new Date().getTime();
Date.now()
var x = Date.now();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new Date().getTime()
Date.now()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new Date().getTime()
562377.7 Ops/sec
Date.now()
575268.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested:** MeasureThat.net is testing two ways to get the current time in JavaScript: `Date.now()` and `new Date().getTime()`. The benchmark aims to determine which method is faster. **Options compared:** There are two options being compared: 1. **`Date.now()`**: This function returns the number of milliseconds since the Unix Epoch (January 1, 1970, 00:00:00 UTC) as an integer. 2. **`new Date().getTime()`**: This expression creates a new `Date` object and returns the timestamp (number of milliseconds since the Unix Epoch) of that date in milliseconds. **Pros and Cons of each approach:** * **`Date.now()`**: + Pros: Simple, efficient, and widely supported. + Cons: Returns the number of milliseconds since the Unix Epoch, which may not be what you want if you need to compare times in a specific context (e.g., relative to midnight). * **`new Date().getTime()`**: + Pros: Returns the timestamp of a specific date object, allowing for more flexibility when comparing times. + Cons: Less efficient and less widely supported than `Date.now()`. **Library used:** None explicitly mentioned in the benchmark definition or test cases. However, it's likely that MeasureThat.net is using a JavaScript engine or browser implementation that provides these functions. **Special JS feature/syntax:** The benchmark uses no special JavaScript features or syntax beyond what is standard for JavaScript. No ES6+ features, async/await, or other advanced constructs are used. **Other alternatives:** If you need to compare times in JavaScript, other options might include: 1. **`performance.now()`**: This function returns the number of milliseconds since the performance measure started. 2. **`Date.prototype.getTime()`**: Some older browsers (e.g., Internet Explorer) may support this method for getting the timestamp. 3. **`Intl.DateTimeFormat().resolvedOptions().timeZone`**: This property is not well-supported across browsers and requires access to the local timezone. In general, `Date.now()` remains a popular choice due to its simplicity and widespread support, but the best approach depends on your specific use case and requirements.
Related benchmarks:
Date.now(); vs new Date().getTime();
Date.now() vs new Date().getTime()
Date.now() vs new Date().getTime(qu)
Date.now() - Date.now() vs new Date() - new Date()
Comments
Confirm delete:
Do you really want to delete benchmark?