From: Jake Jarvis on
Scott Sauyet wrote:
> On Jan 14, 11:41 am, Scott Sauyet <scott.sau...(a)gmail.com> wrote:
>> As to benchmarks, perhaps I will try some.
>
> Ok, I tried. I don't have much experience at JS benchmarks, so there
> may be major flaws in them. I'd appreciate it if someone could point
> out improvements.
>
> I've posted some tests here:
>
> http://scott.sauyet.com/Javascript/Test/LoopTimer/1/test/
>
> These tests run two of the code samples discussed earlier [1, 2]
> multiple times. I try them with initial arrays of length 10, 100,
> 1000, and 10000. I run them, respectively, 100000, 10000, 1000, and
> 100 times, so in each case the number of iterations of the main body
> of the function will happen one million times. (This should lead to
> slightly higher efficiency with larger arrays, as the outer loop has
> to run fewer times, but I suspect that that's only noise in the
> results.) To run this in IE, I could only run one test at a time or
> the browser would alert me of long-running scripts and my running
> times were compromised.
>
> In any case, I report the number of iterations of the tested algorithm
> that run per millisecond.
>
> I collected the results at
>
> http://scott.sauyet.com/Javascript/Test/LoopTimer/1/
>
> But I've done something screwy to IE on the page trying to be clever.
> If anyone can tell me why the generated links are not working properly
> in IE, I would love to know. In other browsers, you can see the
> results, run one of the predefined tests, or choose to run either
> algorithm in your browser, supplying the size of the array and the
> number of iterations to run.
>
> I tested on the browsers I have on my work machine:
>
> Chrome 3.0.195.27
> FF 3.5.7
> IE 8
> Opera 9.64
> Safari 4.0.3
>
> All running on Windows XP on a fairly powerful machine.
>
> The results definitely say that the backward looping algorithm
> supplied by Thomas is generally more efficient than the forward one I
> gave. But there is some murkiness. First of all, the values reported
> as this is run in different browsers (and specifically in their
> ECMAScript implementations, for the pedantic among you) vary hugely.
> They can differ by a factor of 50 or more.
>
> In Opera the backward looping was faster at all array sizes, by an
> approximate factor of 3. In Safari it was faster by a factor of 5.
> In IE, it was faster, but at a factor that decreased as the array size
> increased, down to about 1.21 for a 10000-element array. In Firefox
> and Chrome it was more complicated. For array sizes of 10, 100, and
> 1000 in Chrome, the backward was faster than forward by factors
> approximately 1.5 - 2.5. But for 10000 elements, forward was faster
> by a factor of about 1.25; I checked at 100000 elements too, and
> forward was faster by a factor of about 1.5. In Firefox, backwards
> was faster than forwards for 10 and 100 elements, by a factor of 1.5
> and 2, respectively, but for 1000, forward was faster than backward by
> a factor of 17, and at 10000, forward was faster by a factor of 27.
> It's not that forward improved at higher array sizes in FF but that
> backwards slowed way down.
>
> I did try reversing the order of the tests to see if garbage
> collection had anything to do with this, but it make no substantive
> difference.
>
> The conclusion I can draw from this is that backward is generally a
> better bet, but that might be reversed for higher array sizes, at
> least in FF and Chrome.
>
> So, has anyone got suggestions for improving these tests? Can someone
> tell me what's wrong in IE in my results page?

line 120:

| var size = parseInt(cells[i].textContent, 10) || 1,
^^^^^^^^^^^
No such thing in mshtml

--
Jake Jarvis