Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Time Taken
(version: 0)
Comparing performance of:
Date.now() vs performance.now()
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
Date.now()
const start = Date.now(); const total = Date.now() - start;
performance.now()
const start = performance.now(); const total = performance.now() - start;
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/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Date.now()
5590011.5 Ops/sec
performance.now()
3325166.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The benchmarking process involves measuring the execution time of a specific piece of code or function, and the results are displayed in a user-friendly format. **Benchmark Definition** The provided JSON represents a benchmark definition with two test cases: 1. **Date.now()** 2. **performance.now()** The "Name" field specifies that the benchmark is measuring the time taken for each test case. **Options Compared** Two options are being compared: * **Date.now()**: This function returns the number of milliseconds since the Unix epoch (January 1, 1970) in the current timezone. It's a simple way to get the current time. * **performance.now()**: This function returns the value (in fraction of a second) of a performance counter that represents the amount of time elapsed since an arbitrary start point. **Pros and Cons** Here are some pros and cons for each option: ### Date.now() Pros: * Simple to use * Only requires a single line of code Cons: * May not be suitable for high-performance applications due to the following reasons: * **Accuracy**: The `Date` object's internal timestamp might not be updated at the exact moment when you call `Date.now()`. This can lead to inaccurate results, especially in cases where system time is adjusted manually. * **Precision**: The function returns values with millisecond precision, which may not always be necessary. Higher precision could result in slightly increased overhead due to more frequent updates of the internal timestamp. * **Browser Support**: It has excellent browser support. ### performance.now() Pros: * More accurate than `Date.now()` since it takes into account more factors like system clock adjustments, CPU scheduling, and other non-deterministic events that can impact accuracy in general. It provides higher precision compared to Date.now(), as it returns values with microsecond precision (but not nanosecond). Cons: * Requires a second line of code * Can be slower due to the increased complexity of modern CPUs **Library and Purpose** There is no explicit library mentioned in the benchmark definition. However, the use of `performance.now()` suggests that the developer is aware of and using the performance APIs provided by the browser. The performance APIs are a set of low-level functions for measuring various aspects of JavaScript execution time and other performance metrics. **Special JS Feature or Syntax** Neither of the test cases utilizes any special JavaScript features or syntax. They only utilize built-in functions (`Date.now()` and `performance.now()`). If you were to create a benchmark that utilized some advanced features like async/await, Web Workers, or even micro-optimization techniques (like bit shifting), those would be worth exploring. **Other Alternatives** If you wanted to explore alternatives to the options mentioned above, here are a few: * **Intl.DateTimeFormat**: This API can be used for comparing dates between different languages and locales. However, it might not provide any inherent performance advantage over `Date.now()` when measuring basic timing differences. Please note that these alternatives will have varying degrees of applicability based on the specific requirements of your benchmarking task. Keep in mind that creating a good JavaScript benchmark should take into account several factors, including the system configuration, browser, and other non-deterministic variables.
Related benchmarks:
new Date().getTime() vs Date.now()
+new Date vs new Date().getTime() vs Date.now() 100k
Date.now() - Date.now() vs new Date() - new Date()
performance float vs getTime int
Check Date contains time
Comments
Confirm delete:
Do you really want to delete benchmark?