Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date.now() vs new Date().getTime() vs performance.now()
(version: 0)
Comparing performance of:
Date.now() vs new Date().getTime(); vs performance.now()
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var timestamp = null;
Tests:
Date.now()
timestamp = Date.now();
new Date().getTime();
timestamp = new Date().getTime();
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().getTime();
performance.now()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Goanna/6.8 Firefox/128.0 PaleMoon/34.1.0
Browser/OS:
Pale Moon (Firefox Variant) 34 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Date.now()
6431370.5 Ops/sec
new Date().getTime();
3467737.0 Ops/sec
performance.now()
5046218.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's dive into what's being tested here. **Benchmark Description** The benchmark tests three different ways to get the current timestamp in JavaScript: 1. `Date.now()` 2. `new Date().getTime();` 3. `performance.now()` These methods are compared in terms of their execution speed, measured by the number of executions per second (EPS). **Options Compared** Here's a brief description of each option and its pros/cons: 1. **`Date.now()`**: * Pros: Simple to use, widely supported across browsers. * Cons: Returns the timestamp in milliseconds since January 1, 1970, which might not be suitable for all use cases (e.g., comparing timestamps within a shorter time range). 2. **`new Date().getTime();`**: * Pros: Also returns the timestamp in milliseconds since January 1, 1970. * Cons: More verbose than `Date.now()`, requires creating a new `Date` object. 3. **`performance.now()`**: * Pros: High-resolution timer that provides the most accurate measurement of time elapsed since the start of the browsing session. * Cons: Not supported in older browsers, requires access to the `performance` API. **Other Considerations** When choosing between these options, consider the following: * If you need a simple, widely-supported way to get a timestamp, use `Date.now()`. * If you require high-resolution timing or want to measure time elapsed since the start of the browsing session, use `performance.now()` (if supported). * If you're working with older browsers that don't support `performance.now()`, use `new Date().getTime();` as a fallback. **Library and Special JS Feature** In this case, no external libraries are used. The benchmark only relies on built-in JavaScript methods: `Date.now()`, `new Date()` (constructor), and `performance.now()` (API). No special JavaScript features or syntax are employed in this test. **Alternatives** Other alternatives for getting the current timestamp include: * Using a library like Moment.js or Luxon, which provide more advanced date and time manipulation capabilities. * Utilizing Web APIs like `getUserMedia()` (for measuring time elapsed since the user granted permission) or `requestAnimationFrame()` (for measuring animation duration). * Implementing custom timing mechanisms using JavaScript's built-in `setInterval()` or `setTimeout()` functions. I hope this explanation helps you understand what's being tested and provides a solid foundation for choosing the best approach for your specific use case!
Related benchmarks:
Date.now() vs new Date().getTime()
new Date().getTime() vs Date.now()
Date.now() vs new Date() vs performance.now()
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?