From: Dr J R Stockton on 27 Feb 2010 18:41
com>, Sat, 13 Feb 2010 13:42:39, Hans-Georg Michna <hans-
>run your tests twice. First you get a raw measurement with, say,
>100 iterations. From that you extrapolate the number of
>repetitions you need for some desired total time and run the
>test again with that number.
>This way the new Date() calls will have no effect on your
>measurements, because there will be none inside the loop.
>To deduct the loop counter and test time, you can determine and
>subtract the time needed for an empty loop.
If this testing is being taken really seriously, it might be wise to do
it on a specially-configured boot of the system such that a minimum of
other processes are being run. The fewer other processes that might
grab the CPU, the more accurate the results are likely to be.
One can, instead of what you suggest, extrapolate the number for 1/Nth
of the total time, and measure N times; but do it contiguously so that
there are only N+1 calls of new Date(). The answer will still be
obtained from the difference between the last and first times; but by
checking that the partial answers do not vary too much, one can protect
against believing an answer that is unusually influenced as in the
Choose to use, as much as possible, a system that gives good and
meaningful resolution in new Date().
<URL:http://www.merlyn.demon.co.uk/js-dates.htm#Ress> indicates what I
mean, but needs updating - results for Vista and Windows 7 are lacking.
On my WinXP, Firefox apparently has a resolution of 1 ms, Opera of 1/64
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
From: Hans-Georg Michna on 28 Feb 2010 04:31
On Sat, 27 Feb 2010 23:41:52 +0000, Dr J R Stockton wrote:
>One can, instead of what you suggest, extrapolate the number for 1/Nth
>of the total time, and measure N times; but do it contiguously so that
>there are only N+1 calls of new Date().
My proposal was directed at avoiding Date() altogether inside
the loop. I guess that something like
for (i = 0; i < 10000; i++) ...
is much faster and less distorting than Date(), which delves
into the operating system and may cause unpredictable delays.
One just has to replace 10000 with a suitable number, and that's
not difficult. For a few tests one could do it manually, by
trial and error. For a more systematic approach one would use a
reasonably low number for a first run and extrapolate the number
for the second, final run from that.
From: Dr J R Stockton on 1 Mar 2010 11:39
com>, Sun, 28 Feb 2010 10:31:32, Hans-Georg Michna <hans-
>On Sat, 27 Feb 2010 23:41:52 +0000, Dr J R Stockton wrote:
>>One can, instead of what you suggest, extrapolate the number for 1/Nth
>>of the total time, and measure N times; but do it contiguously so that
>>there are only N+1 calls of new Date().
>My proposal was directed at avoiding Date() altogether inside
>the loop. I guess that something like
> for (i = 0; i < 10000; i++) ...
>is much faster and less distorting than Date(), which delves
>into the operating system and may cause unpredictable delays.
>One just has to replace 10000 with a suitable number, and that's
>not difficult. For a few tests one could do it manually, by
>trial and error. For a more systematic approach one would use a
>reasonably low number for a first run and extrapolate the number
>for the second, final run from that.
That leaves you at the mercy of interventions by the OS.
On my P4/3GHz, using Firefox 3.0.18, new Date() takes about 2.5 us; in
Chrome 4.0, it takes 0.4 us. A few of those, during a timing run taking
an appreciable fraction of a second, will not matter.
Another approach would be to use (cf. above)
for (i = 0; i < imax; i++)
and to start with imax = 1, doubling it until the interval became
adequate and then doing a few tests with that imax, checking that they
are in reasonable agreement.
The time for an empty loop should be carefully measured and subtracted.
ECMA should be pressed to add to the language a global function (or ?)
which accesses the finest available time counter of the system. On a
modern PC, a single machine instruction will read a 64-bit CPU since-
boot cycle count, and its nominal frequency is also IIRC available.
Should be easy to implement, if the result is specified as machine-
dependent or 0/false if not available. Only the low 53 bits need be
returned in that case (2^64 at 10GHz is over 60 years, 2^53 is over 10
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
From: Thomas 'PointedEars' Lahn on 6 Mar 2010 16:45
Scott Sauyet wrote:
> David Mark wrote:
>> Scott Sauyet wrote:
>>> Things like this are very convenient:
>>> select("div.navigation a:not(li.special a)");
>> Honestly, that looks ludicrous to me.
> Okay, it might look that way to you. To me it is a very concise and
> intuitive way to say "select all the anchor elements that are inside
> divs with a class of navigation but are not inside list items with a
> class of special, and by the way, return them in document order,
> please." That was the requirement.
The question remains, though, did the requirement make sense in the first
place? Was it really not possible to solve this problem differently, for
example with event bubbling, with using the CSS cascade, with using
standards-compliant event-handler attributes, or a combination of them?
And then, is the approach that had been chosen to meet the requirement more
or at least equally reliable than the alternatives?
The answer to the first question is very likely "no". The answers to the
second and third question are definitely "no".
As for the second one, if you lose the rather unreasonable notion of having
to separate markup and the script written specific for that markup, of
having to add event listeners dynamically, especially with server-side
scripting, or select elements with client-side scripting only to modify
their presentation globally (that is what the CSS cascade is for and you
can, very easily and interoperably, add new stylesheets to override the
And as for the third one, no approach that depends on the availability of
API features to define event listeners in the first place, especially not
on those being proprietary (MSHTML does not support W3C DOM Events to date)
can ever be more reliable than one that uses only or mostly standards-
compliant, well-defined and proven-to-be-interoperable features like event-
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: "Michael Haufe ("TNO")" on 6 Mar 2010 19:08
On Mar 1, 10:39 am, Dr J R Stockton <reply1...(a)merlyn.demon.co.uk>
> The time for an empty loop should be carefully measured and subtracted.
This approach would assume that the implementation in question doesn't
optimize away the loop as a useless construct.