Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
perfomance.now vs Date.now vs new Date().getTime()
(version: 0)
Comparing performance of perfomance.now, Date.now and new Date().getTime()
Comparing performance of:
performance.now() vs Date.now() vs new Date().getTime();
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var timestamp = null;
Tests:
performance.now()
timestamp = performance.now();
Date.now()
timestamp = Date.now();
new Date().getTime();
timestamp = new Date().getTime();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
performance.now()
Date.now()
new Date().getTime();
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser/OS:
Chrome 119 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
performance.now()
4835789.0 Ops/sec
Date.now()
7312670.0 Ops/sec
new Date().getTime();
6815347.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **What is being tested?** The benchmark compares the performance of three different methods to get the current timestamp in JavaScript: 1. `performance.now()` 2. `Date.now()` 3. `new Date().getTime()` These methods are designed to provide the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC) or since the system started running, respectively. **Options compared** The three options are being compared in terms of their performance (in executions per second) on a specific browser and device platform: * `performance.now()`: This method uses the Web API's `performance` object to get the current timestamp. It is designed to be more precise than other methods, especially for high-frequency applications like gaming or real-time analytics. * `Date.now()`: This method uses the built-in `Date` object to get the current timestamp. It is a simple and widely supported approach but can be less precise than `performance.now()` due to its reliance on the system clock. * `new Date().getTime()`: This method creates a new `Date` object and calls its `getTime()` method to get the current timestamp. Like `Date.now()`, it relies on the system clock, which can introduce variability and less precision compared to `performance.now()`. **Pros and Cons of each approach** * **performance.now()** + Pros: - High precision (typically 15-16 decimal places) - Optimized for high-frequency applications - Provides a more accurate representation of time elapsed since the last call + Cons: - May be slower due to the overhead of accessing the Web API's performance object - Less widely supported on older browsers or platforms * **Date.now()** + Pros: - Simple and widely supported (across all modern browsers and platforms) - Fast execution time + Cons: - May introduce variability due to system clock inaccuracies - Less precise than `performance.now()` (typically 10 decimal places) * **new Date().getTime()** + Pros: - Simple and widely supported (across all modern browsers and platforms) - Fast execution time + Cons: - May introduce variability due to system clock inaccuracies - Less precise than `performance.now()` (typically 10 decimal places) **Library usage** None of the benchmark's test cases use any external libraries. **Special JS features or syntax** The benchmark uses the `performance` object, which is a Web API feature specifically designed for high-performance applications. The `new Date().getTime()` method also relies on JavaScript's built-in `Date` object and its `getTime()` method. **Other alternatives** If you need to get the current timestamp in JavaScript without relying on these methods, some alternative approaches exist: * Using the `Intl.DateTimeFormat` API or a polyfill for older browsers (e.g., IE 8-9) * Utilizing the `Date.now()` method with optional timestamp adjustments (e.g., using `Math.floor()` to round down to milliseconds) * Implementing a custom timestamp generator based on the system clock Keep in mind that these alternatives may have performance trade-offs or limitations, and it's essential to evaluate their suitability for your specific use case.
Related benchmarks:
Date.now() vs new Date().getTime()
new Date().getTime() vs Date.now()
Date.now() - Date.now() vs new Date() - new Date()
perfomance.now vs Date.now vs +new Date()
Comments
Confirm delete:
Do you really want to delete benchmark?