I've made a selector library at https://github.com/minitech/Sprint.js and it appears to be much slower than jQuery on the ID selectors #test
and #test2
, and on the selector *
. Can anyone point out some optimizations that could be made to make it faster?
|
|||
add comment |
I have not done measurements to see how much this matters, but I can see in stepping through a simple selector operation in your library and in jQuery that you have two regex operations and a string trim whereas jQuery has only a single regex operation. You have a trim to remove extra whitespace, a regex to find the simple Further, your unescape function uses a regex that is not precompiled so it has to be compiled from scratch each time. Edit: I've now done some measurements. Without modification, I find your function very similar in performance to jQuery in several different modern browsers (Firefox, Chrome, IE9). If I remove the escape and the trim, your library benchmarks faster than jQuery here in each browser I tried: http://jsperf.com/sprint-selector-id-benchmark. |
||||
|
#test
to just calldocument.getElementById()
. Are you doing that? – jfriend00 Nov 1 '11 at 0:18sprint("#id")
and you don't cache the live nodelist returned from "*" – Raynos Nov 1 '11 at 0:30"*"
and it actually worsens performance. Odd, but true. – minitech Nov 1 '11 at 2:16