Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
perfomance.now vs Date.now vs +new Date()
(version: 0)
Comparing performance of:
performance.now(); vs Date.now(); vs +new Date();
Created:
one year 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();
timestamp = +new Date();
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();
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
performance.now();
2651687.5 Ops/sec
Date.now();
3647844.8 Ops/sec
+new Date();
2652194.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmarking scenario you've provided. **What is being tested?** The benchmark is testing three different ways of getting the current timestamp in JavaScript: `performance.now()`, `Date.now()`, and `+new Date()`. The test aims to compare the performance of these three methods, specifically their execution speed. **Options compared:** 1. **`performance.now()`**: This method returns the number of milliseconds since the high-resolution timer was activated on the system, which is a more accurate way of measuring time than traditional timestamps (e.g., `Date.now()`). 2. **`Date.now()`**: This method returns the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC), which is a widely used and well-established timestamp. 3. **`+new Date()`**: This method creates a new `Date` object and uses its `getTime()` method to get the timestamp, effectively subtracting 1 from the result of `new Date()`. This is an older way of getting timestamps in JavaScript. **Pros and cons:** * **`performance.now()`**: * Pros: * More accurate than traditional timestamps. * Better suited for measuring short periods of time or performance. * Cons: * Not supported on older browsers (e.g., IE). * Requires modern JavaScript engines. * **`Date.now()`**: * Pros: * Widely supported across browsers and platforms. * Suitable for general-purpose timestamping. * Cons: * Less accurate than `performance.now()`, especially for short periods. * **`+new Date()`**: * Pros: * Wide support across browsers and platforms, including older ones. * Simple syntax. * Cons: * Inaccurate due to the subtraction of 1 from the result. **Library and purpose:** None are explicitly mentioned in this benchmark. However, `performance.now()` is a built-in JavaScript method that provides high-resolution timing capabilities. **Special JS feature or syntax:** There's no specific JavaScript feature or syntax being tested here; it's simply about comparing the performance of different ways to get timestamps. **Other alternatives:** If you need alternative methods for getting timestamps, some options include: * **`new Date().getTime()`**: Similar to `+new Date()`, but using the `getTime()` method directly on the new `Date` object. * **`Intl.DateTimeFormat().resolvedOptions().timeZone`**: A more modern approach that uses the `Intl.DateTimeFormat()` API to get the timestamp, taking into account time zones. Keep in mind that these alternatives might not be as accurate or widely supported as `performance.now()`. Always consider your specific use case and requirements when choosing a method for getting timestamps.
Related benchmarks:
Date.now() vs new Date().getTime()
Date.now() vs new Date()
Date.now() vs new Date
Date.now() - Date.now() vs new Date() - new Date()
Date.now() vs +new Date() test
Comments
Confirm delete:
Do you really want to delete benchmark?