Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
+new Date vs new Date().getTime() vs Date.now() 100k
(version: 0)
testing performance of +new Date vs new Date().getTime() vs Date.now() with 100k iteration
Comparing performance of:
+new Date vs new Date().getTime() vs Date.now()
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
+new Date
for(let i = 0; i < 100000;i++){ +new Date; }
new Date().getTime()
for(let i = 0; i < 100000;i++){ new Date().getTime(); }
Date.now()
for(let i = 0; i < 100000;i++){ Date.now() }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
+new Date
new Date().getTime()
Date.now()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
+new Date
130.4 Ops/sec
new Date().getTime()
253.4 Ops/sec
Date.now()
300.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into explaining the benchmark and its components. **What is tested:** The provided JSON represents a set of benchmarks that test the performance of three different ways to get the current timestamp in JavaScript: 1. `+new Date` 2. `new Date().getTime()` 3. `Date.now()` These methods are used to measure the execution time and frequency of these functions. **Options compared:** The three options are compared in terms of their performance, which is measured by the number of executions per second (ExecutionsPerSecond) on a specific browser, device platform, and operating system. **Pros and Cons:** Here's a brief overview of each option: 1. `+new Date`: * Pros: Simple and concise syntax. * Cons: Creates a new Date object every time it's used, which can lead to performance issues if not optimized correctly. 2. `new Date().getTime()`: * Pros: Returns the timestamp as a numeric value, allowing for more precise comparisons. * Cons: Creates a new Date object and then calls its `getTime` method, which can be slower than other options. 3. `Date.now()`: * Pros: Native to JavaScript and optimized for performance. * Cons: May not work in older browsers or environments that don't support it. **Library:** There is no external library used in this benchmark, as all three options are native JavaScript functions. **Special JS feature or syntax:** None of the options use any special JavaScript features or syntax. They only rely on standard JavaScript functionality. **Other alternatives:** If you need to compare other methods for getting the current timestamp, some alternative approaches include: * `Date.now()` (as mentioned earlier) * `performance.now()` (available in modern browsers and Node.js environments) * Using a third-party library like Moment.js or Luxon * Implementing your own custom timestamp function **Benchmark preparation code:** The benchmark preparation code is not provided, but it's likely that the script generates 100k iterations of each test case using a loop. **Individual test cases:** Each test case consists of a single execution of one of the three options, repeated 100k times. This allows for a simple and straightforward comparison of their performance. I hope this explanation helps you understand the benchmark and its components!
Related benchmarks:
new Date().getTime() vs Date.now()
new Date vs performance.now
Date.now() vs new Date() vs performance.now()
Date.now() vs new Date().getTime(qu)
Date.now() - Date.now() vs new Date() - new Date()
Comments
Confirm delete:
Do you really want to delete benchmark?