Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date.now() vs new performance.now()
(version: 0)
Comparing performance of:
Date.now() vs performance.now()
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var timestamp = null;
Tests:
Date.now()
timestamp = Date.now();
performance.now()
timestamp = performance.now();
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:
10 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Browser/OS:
Firefox 139 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Date.now()
13079361.0 Ops/sec
performance.now()
5332423.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **Benchmark Definition JSON** The provided benchmark definition JSON represents two test cases, each comparing different approaches to measure time in JavaScript. 1. **"Date.now()"**: This test case measures the execution time of `Date.now()` without any modifications. 2. **"performance.now()"**: This test case measures the execution time of `performance.now()` without any modifications. **Options Compared** The two options being compared are: * **`Date.now()`**: A built-in JavaScript function that returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. * **`performance.now()`**: A high-resolution timer provided by the `Performance` API, which returns the elapsed time in fractional seconds. **Pros and Cons** Both options have their advantages and disadvantages: * **`Date.now()`**: * Pros: * Widely supported across browsers and devices. * Simple to use and understand. * Cons: * May not provide the most accurate results due to various factors like system clock adjustments, time zone changes, and more. * Can be affected by the browser's scheduling algorithm, which might introduce variability in the measurements. * **`performance.now()`**: * Pros: * Provides high-resolution timing with better accuracy compared to `Date.now()`. * Reduces the impact of factors that can affect `Date.now()`, resulting in more reliable results. * Cons: * Not all browsers support this API, and older versions might not work correctly. * May require additional setup or configuration to access this API. **Library** In the test cases provided, no libraries are explicitly mentioned. However, `Performance` API is part of the standard JavaScript library in modern browsers. **Special JS Features or Syntax** The benchmark uses the `var timestamp = null;` syntax for variable declaration and assignment. This is a valid JavaScript feature that allows for block-level scope and redeclaration without error. It's used here to initialize the `timestamp` variables before measuring their execution times. **Benchmark Preparation Code** The preparation code, `"var timestamp = null;"`, sets up a blank scope where the benchmark function can be executed. In the first test case, it prepares to measure the time taken by `Date.now()`. In the second test case, it prepares to measure the time taken by `performance.now()`. **Latest Benchmark Result** The latest result shows the execution times for both tests in Firefox 107 on a Mac OS X 10.15 desktop: * **`Date.now()`**: Approximately 9.46 million executions per second. * **`performance.now()`**: Approximately 5.81 million executions per second. These results indicate that `performance.now()` generally provides more accurate timing due to its higher resolution and reduced impact from factors like system clock adjustments or scheduling algorithms. **Alternatives** If you're looking for alternatives, here are a few options: * **`Date.now()`**: Useful for general-purpose timing needs but might not be suitable for high-precision applications. * **`performance.now()`**: Ideal for measuring time intervals in fractional seconds and is recommended for most use cases where accuracy is crucial. Keep in mind that the choice between these two methods depends on your specific requirements, the level of precision needed, and the compatibility with different browsers and devices.
Related benchmarks:
Date.now() vs new Date().getTime()
Date.now() vs new Date() vs performance.now()
Date.now() vs new Date()
Date.now() - Date.now() vs new Date() - new Date()
Comments
Confirm delete:
Do you really want to delete benchmark?