Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date.now() vs new Date().getTime() vs performance.now() with calc
(version: 0)
Comparing performance of:
Date.now() vs new Date().getTime(); 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() - Date.now();
new Date().getTime();
timestamp = new Date().getTime() - new Date().getTime();
performance.now()
timestamp = performance.now() - performance.now();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Date.now()
new Date().getTime();
performance.now()
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is tested on the provided JSON?** The benchmark tests three different ways to get the current timestamp in JavaScript: 1. `Date.now()`: This method returns the number of milliseconds since the Unix Epoch (January 1, 1970) as an integer. 2. `new Date().getTime()`: This method also returns the number of milliseconds since the Unix Epoch, but it's a separate object and its `getTime()` method is called to get the timestamp. 3. `performance.now()`: This method returns the number of milliseconds since the performance measurement started. All three methods are compared in terms of their execution time, measured as the number of executions per second (ExecutionsPerSecond). **Options compared** The benchmark compares the following options: * The speed of each method when used to calculate a simple timestamp calculation (`timestamp = Date.now() - Date.now();`) * The speed of each method in general usage (i.e., not just for this specific calculation) **Pros and cons of each approach:** 1. `Date.now()`: This method is generally the fastest because it's a native JavaScript function that doesn't require any object creation or method calls. * Pros: Fastest, most efficient * Cons: Not as intuitive as other methods (it returns an integer), not suitable for precise timestamp calculations 2. `new Date().getTime()`: This method is slightly slower than `Date.now()` because it creates a new Date object and then calls its `getTime()` method. * Pros: More intuitive, can be used for precise timestamp calculations * Cons: Slightly slower, more object creation overhead 3. `performance.now()`: This method is also slower than `Date.now()` because it measures the performance measurement time and not just returns a timestamp. * Pros: Suitable for measuring time intervals or precise timestamp calculations * Cons: Slower, less intuitive **Library usage** There are no libraries used in this benchmark. **Special JS features or syntax** None of these methods rely on special JavaScript features or syntax. They are all part of the standard JavaScript API. **Other alternatives** Other alternatives for getting a timestamp in JavaScript include: * `Date.now()` (already tested) * `new Date().getMilliseconds()` * `performance.now()` (already tested) * `RequestAnimationFrame` (not tested, but can be used to measure time intervals) It's worth noting that there are also some polyfills available for older browsers that may not support these methods.
Related benchmarks:
Date.now() vs new Date().getTime()
new Date().getTime() vs Date.now()
Date.now() vs new Date() vs performance.now()
Date.now() - Date.now() vs new Date() - new Date()
Comments
Confirm delete:
Do you really want to delete benchmark?