8 ms·
It's a small difference, but these small differences version after version add up to a lot of nickels. As I mentioned in another comment, increasing performanc
by mpd 14y ago
It's a small difference, but these small differences version after version add up to a lot of nickels.
As I mentioned in another comment, increasing performance for ID selection (which is already much, much faster than other types) at the expense of other types makes for sexy benchmarks, but is less than stellar in the real world.
- kvnn 14y agoThis is nonsense. Making a huge increase in one type of selector for the sake of an insignificant decrease in another selector is an obvious win.
- bzbarsky 14y agoLet's do a simple thought experiment. You have two selectors A and B. A takes 100x more time to evaluate than B (which is about how id and class selectors compare). You evaluate them equally often, say N times each. If the time B takes to evaluate is t, your total execution time is 101t. Now someone comes along and makes B 10x faster while making A 2% slower (which is what the numbers above seem to show for the class selector). Now your execution time is 102.1t, which happens to be larger than 101t. The upshot of all this is that if use frequencies are equal, performance improvements for slow things (even small ones) are worth a lot more than performance improvements for things that are already fast. Now obviously you have to weight by frequency of use, which may differ for different API consumers. There's only one case in which speeding up already-fast stuff at the cost of slow stuff getting even slower is an obvious win regardless of use frequency: benchmarks averaged using geometric means. Which is the most popular averaging method, of course: see Dromaeo, V8 benchmark, PeaceKeeper, etc.
- bzbarsky 14y agoJust out of curiousity, have you considered using querySelector or querySelectorAll directly for your really hot cases? There's a good chance that it'll be faster than the jQuery version in the non-ID cases.
- mpd 14y agoYeah, that's one of the first steps if a selection benchmarks slowly. I just dislike adding complexity in any form. It adds up so quickly in complex software.