Why is Date comparison so much slower than comparing against the result of getTime?
27 views
Skip to first unread message
Matthew Caruana Galizia
unread,
Oct 5, 2012, 12:30:31 PM10/5/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to v8-u...@googlegroups.com
One of my colleagues wrote a test that shows that comparing two Date objects is ~95% slower than comparing against the result of getTime. Why is this so?
Florian Schneider
unread,
Oct 8, 2012, 6:10:15 AM10/8/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to v8-u...@googlegroups.com
This is expected: When comparing two objects like Date with <, they are converted into primitive values (numbers) first. This ToPrimitive-conversion takes most of the time when comparing two Date objects. Comparing the result of getTime() on the other hand is just a comparison of two numbers which is way more efficient.
One of my colleagues wrote a test that shows that comparing two Date objects is ~95% slower than comparing against the result of getTime. Why is this so?
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to v8-u...@googlegroups.com
Thanks, that bit makes sense. Though doesn't getTime() produce a number and if so what's the difference between an explicit and implicit conversion to a primitive value?