Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
date now performance
(version: 1)
Comparing performance of:
Date.now() vs performance.now
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var timedif = null; var precalculated = Date.now()
Tests:
Date.now()
timedif = Date.now()
performance.now
timedif = precalculated - precalculated
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Date.now()
performance.now
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/134.0.0.0 Safari/537.36 OPR/120.0.0.0 (Edition developer)
Browser/OS:
Opera 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Date.now()
4313887.0 Ops/sec
performance.now
6486390.5 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark defined in the provided JSON is aimed at comparing the performance of two different methods of measuring the current time in JavaScript: `Date.now()` and `performance.now`. ### Options Compared 1. **Date.now()** - **Benchmark Definition**: `timedif = Date.now()` - **Description**: This is a method that returns the current timestamp in milliseconds since the Unix epoch (January 1, 1970). - **Performance Result**: In the benchmark results, `Date.now()` achieved approximately 12,534,247 executions per second. 2. **performance.now** - **Benchmark Definition**: `timedif = precalculated - precalculated` - **Description**: This method returns a timestamp measured in milliseconds, but with sub-millisecond precision (floating-point number) since the time origin (time since the navigation started). The subtraction of the same variable (`precalculated - precalculated`) effectively returns 0, which is a placeholder for measuring the execution performance of `performance.now`. - **Performance Result**: In this benchmark, `performance.now` achieved approximately 897,254,144 executions per second. ### Pros and Cons of Approaches #### Date.now() - **Pros**: - Simple and widely used for measuring non-critical time events. - Returns time in a straightforward way in milliseconds. - **Cons**: - It has lower precision compared to `performance.now()`, which might not be suitable for high-resolution time measurements needed in animations, high-frequency operations, or performance testing. - Availability may differ in older environments (though it is broadly supported now). #### performance.now - **Pros**: - Provides a higher precision (sub-millisecond) timestamp, which is critical for performance measurements and can deliver more accurate results in benchmarking and timing operations. - It is designed specifically for performance timing and is ideal for tasks that require high resolution. - **Cons**: - Slightly more overhead in terms of usage compared to `Date.now()`, although this is often negligible given its performance advantage. - The format of the returned value (floating point) may require additional handling for certain time calculations when compared to the integer value returned by `Date.now()`. ### Other Considerations - While `Date.now()` may be more commonly used in everyday JavaScript applications due to its simplicity, `performance.now()` is recommended for scenarios where precise timing is essential, such as animations, gaming, and performance measurements. ### Alternatives - Aside from `Date.now()` and `performance.now()`, if extremely high precision timing is necessary, developers could consider additional libraries or APIs designed for performance profiling, like the `window.performance` object which provides methods for measuring performance, or using the same `performance.now()` in combination with advanced performance analysis tools. - Other alternatives for specific use cases might include using high-resolution timers in Node.js (like `process.hrtime`), but that is outside the scope of browser-based JavaScript. ### Conclusion This benchmark illustrates the significant performance difference between the two timing methods, highlighting how `performance.now()` can be virtually an order of magnitude faster than `Date.now()`. For precise performance measurements, especially in modern web applications, `performance.now()` is the preferred method.
Related benchmarks:
Date vs date time
Date.now() vs performance.now()324234
Date object
new Date() vs Date.now()
Date parsing performance
2222222222222222222222222221`
Date.now() vs +new Date() test
Date.now() vs +new Date() testing
Date Creation2
Comments
Confirm delete:
Do you really want to delete benchmark?