Scott Sauyet wrote:
Based on the SlickSpeed tests John-David Dalton recently demonstrated,
I've created my own new version of SlickSpeed. It uses essentially
the same timer-loop method as he did, but then calculates and reports
the time per iteration in microseconds, totaling them in milliseconds
so that the final report looks more like the original one: smaller is
better again!
I've chosen to run the test repeatedly until it's
taken over 250 ms, which seems to give a reasonably good balance
between accuracy and performance; the original 40 selectors take about
10 seconds per library tested.
Okay.
There is still one flaw that Richard Cornford pointed out [1]: the
loop also includes repeated calls to "new Date()". This will serveto
slow down all libraries and somewhat downplay the differences between
them. I'm considering ways to fix it, but for the moment it shouldn't
affect rankings, only the speed ratios between the libraries.
Makes sense. The difference is what matters.
My first pass at this is at:
http://scott.sauyet.com/Javascript/Test/slickspeed/2010-02-12a/
I've tried it once so far (just now) in FF1 on XP Pro on a PC that is
over five years old.
2013.922 ms 4572.244 ms 3763.426 ms 1618.309ms* 1431.766 ms*
1665.66 ms 75786.916 ms
I don't know what happened with YUI. But it was only one run. Too many
pink boxes (slowest) to think it will come out of it though. Prototype
didn't do too bad, but was disqualified for miscounting :contains
(unless they have stipulated that they do not support that selector).
I take issue with the inclusion of tests that are not supported by all
of the libraries. Doesn't make a lot of sense as not every library
claims to support the exact same set of selectors. For example, 2n and
2n + 1 are things I didn't feel like bothering with. I just can't see
getting that silly with this stuff. There are certainly many other CSS3
selectors that I do not (and will not) support for querying. If you
want more than what is supported, write an add-on (it's very easy to do
as the QSA addition illustrates).
There is a link in the footer to a zip file containing the PHP code
used.
My raw results are below, run against recent versions of the major
browsers on a powerful Windows XP machine.
Okay.
While this is still not a
home run for My Library, it's definitely getting to be a closer
contest on my developer's machine, at least with QSA.
With QSA it will always be a tight race, likely so tight that the
differences are unimportant. It's when the library has to "thunk" back
to DOM traversal that the difference vary widely. And that's important
as most browsers in use today do not support QSA at all (and those that
do do it less than perfectly).
While I
understand and partially agree with John-David's objections to the
current My Library QSA code [2], I think it's good enough for this
sort of testing at the moment, and I doubt the fixes to it will change
much in the way of speed.
I think a lot of the "fixes" would simply be adding support for
selectors that I don't deem worthy of support. Not all, of course, he
did notice some valid peculiarities and some of them have been fixed in
the interim.
The big news is that in these tests, in all browsers, except IE6 and
IE8 in compatibility mode, My Library (QSA) was the fastest for a
majority of the selectors.
I'm not surprised. Nor am I surprised that broken MSHTML
implementations are the exceptions. Those are where the wheels falloff
for every one of the others. Put a few choice attribute-related rules
in and they will predictably break down and veer off the course. And
these are obviously selectors they assert to support (and have asserted
so for some time). That's not good, especially when Web developers are
now being conditioned to "forget" IE < 8 (and as we know, IE8
compatibility mode is roughly equivalent to IE7).
But in none was it the overall fastest. JQuery was the fastest in
everything but IE6, where it came in third behind Dojo and MooTools.
In many browsers, if two of the selectors were optimized to match the
speed of the competition, My Library (QSA) would have been about the
fastest overall library. Those were the two selectors with
":contains": "h1[id]:contains(Selectors)" and
"p:contains(selectors)". In the various IE's there was a different
issue, "p:nth-child(even/odd)" were wrong in both versions of My
Library, and were significantly slower, too.
The even/odd discrepancy, which did not show up in my (obviously
incomplete) testing is a legitimate beef. Apparently I managed to make
those both slow and incorrect. It can happen. I'll grab your test page
as an example and fix it when I get a chance. Will also announce that
those two are broken in my forum. As far as I am concerned, the results
are disqualified until those two are fixed.
However, the inclusion of not:, 2n, 2n + 1 is misleading as I never
claimed to support those. That's why they are absent from my test page.
Well, the first was never there in the first place. I'm _not_ adding
that.