4 ms·
I use class selection most often, so any slowdown there is a cause of concern for me. The other slowdowns are not as big of a deal, providing it means speedups
by mpd 14y ago
I use class selection most often, so any slowdown there is a cause of concern for me. The other slowdowns are not as big of a deal, providing it means speedups in more important places.
- dmethvin 14y agoOn my system these are the results for the class selector test: 1.7.2 4,123 ops/s 242 microseconds/op 1.8.0 4,061 ops/s 246 microseconds/op Are you seeing some large difference? You'd need to be selecting things by class several hundreds of times a second before it could possibly make a difference. In practical terms, the speedup in custom selectors is probably the most important, since they are so slow.
- mpd 14y agoIt'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.