Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16435
| From | Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: silly question on Date value evaluation or comparison |
| Date | 2012-10-06 19:06 +0100 |
| Organization | Home |
| Message-ID | <hqowShC1MHcQFwtg@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | (3 earlier) <k3u1v3$kq2$1@dont-email.me> <+LUQ77IMbLZQFwll@invalid.uk.co.demon.merlyn.invalid> <dea8cd7c-f0b0-4fb9-ad55-22e749e17e31@googlegroups.com> <Gid5A8J8cdbQFwwl@invalid.uk.co.demon.merlyn.invalid> <c1c0835f-07fb-4ba1-943e-627a24f1dcd4@n9g2000yqn.googlegroups.com> |
In comp.lang.javascript message <c1c0835f-07fb-4ba1-943e-627a24f1dcd4@n9
g2000yqn.googlegroups.com>, Fri, 5 Oct 2012 13:21:22, Scott Sauyet
<scott.sauyet@gmail.com> posted:
>Dr J R Stockton wrote:
>> [ ... ] IMHO new Date("2012/10/03") is better than
>> new Date(2012,9,3), because it looks like what it means (and in my FF
>> 15.0.1, WinXPsp3, it seems about 10% faster).
>>
>> That format works in every browser that I've tried; no-one has reported
>> that, in any of my pages, it fails; and I've mentioned it often enough
>> here without being told of any failures either. Granted, the ECMA specs
>> do not *require* it to work. And it is good to show non-FFF dates to
>> the chronologically backward.
>
>It is generally faster in implementations I've tested:
>
> <http://jsperf.com/date-constructor-comparison>
>
>It's very slightly faster in FF15 and IE8, very slightly slower in
>FF10, and much faster in Chr19, all on WinXPsp3. It's also much
>faster on my Android phone.
>
>But that's not the end of the story. If you were doing this from
>source code, I would grant you that this is a much cleaner way to
>construct Dates. But if you need to construct dates from existing
>data, there are other issues to consider. This:
>
> var year = 2012, month = 9, day = 3;
> var date = new Date(2012, 9, 3);
>
>is much cleaner than this:
>
> var year = 2012, month = 9, day = 3;
> var oneIndexedMonth = month + 1;
> var date = new Date(year + "/" + (oneIndexedMonth < 10 ? "0" : "")
>+
> oneIndexedMonth + "/" + (day < 10 ? "0" : "") +
>day);
>
>and the performance is much less clear:
>
> <http://jsperf.com/date-constructor-comparison2>
>
>Here the string-building costs enough to drive the performance well
>below that of the multi-parameter constructor technique, at least in
>FF and IE. In Chrome, the single String, even when built this way, is
>somewhat faster (some JIT compiling here?), and in Android it's still
>substantially faster.
>
>So I don't think the choice is as clear as you suggest, except in the
>case that you're constructing a Date object in the source code.
And the case I was considering was indeed that of writing a fixed date
in the source code. Where the date is in variables Y M D, constructing
a string makes little sense - but it can often be seen in pages written
by amateurish coders, such as are employed in PR departments.
I recall a page of one national laboratory (foreigners) which actually
used three digit years in JavaScript for recent dates ... admittedly in
comment. They also constricted a date string from the results of
getFullYear, getUTCmonth, ... with amusing results at year rollover.
That code is gone; IIRC they now use Jquery or suchlike.
Does anyone here read Latin?
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
silly question on Date value evaluation or comparison justaguy <lichunshen84@gmail.com> - 2012-09-25 17:21 -0700
Re: silly question on Date value evaluation or comparison Christoph Becker <cmbecker69@gmx.de> - 2012-09-26 02:36 +0200
Re: silly question on Date value evaluation or comparison justaguy <lichunshen84@gmail.com> - 2012-09-25 18:39 -0700
Re: silly question on Date value evaluation or comparison "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-26 07:57 +0300
Re: silly question on Date value evaluation or comparison Dr J R Stockton <reply1239@merlyn.demon.co.uk.invalid> - 2012-09-27 21:27 +0100
Re: silly question on Date value evaluation or comparison RobG <rgqld@iinet.net.au> - 2012-10-03 00:12 -0700
Re: silly question on Date value evaluation or comparison Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-04 19:36 +0100
Re: silly question on Date value evaluation or comparison Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-05 13:21 -0700
Re: silly question on Date value evaluation or comparison Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-06 19:06 +0100
Re: silly question on Date value evaluation or comparison "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-07 08:03 +0000
Re: silly question on Date value evaluation or comparison Patricia Shanahan <pats@acm.org> - 2012-10-07 09:48 +0100
Re: silly question on Date value evaluation or comparison "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-07 10:09 +0000
Re: silly question on Date value evaluation or comparison Gregor Kofler <usenet@gregorkofler.com> - 2012-09-26 09:11 +0200
csiph-web