findCSS

findCSS is an open source(MIT license) javascript query library to return an array of elements based off of CSS selectors. It's main page is at http://code.google.com/p/findcss/. You can find all documentation, SVN access info, and downloads there.

Why?

I wrote findCSS as a learning experience mainly. I wanted to figure out how things like jQuery, and cssQuery worked. I also wanted a library that made a good compromise between code size and speed.

Comparisons

As you might know there are quite a few libraries out there that accomplish this task, but everyone of them(including mine) has its flaws. The major problem I have with most of them is that they are part of a larger library. This is great if you would like to make use of the libraries other features, but it is ridiculous to include a 70kb javascript file to accomplish this. That means jQuery, Prototypes $$ function, and DomQuery all won't work for me. The only stand-alone library I know of is cssQuery, and compared to the others cssQuery is quite slow. So how does findCSS compare? Well, it isn't exactly small, but it does come in under 6kb(compressed). Speed-wise, findCSS is blazing fast in Firefox and Opera, but can be slow(er) in Internet Explorer(no xpath support). Another limitation in findCSS is that it does not even attempt to support xpath syntax( or some other more advanced features).

Benchmarks

Before I actually give you the benchmark results, let me say thanks to jQuery(http://jquery.com/blog/2007/01/11/selector-speeds/), because I used their comparison suite to get these results. Also, each test was run 5 times. findCSSx does not use xpath, whereas findCSS does. Now on to the results.

Firefox

Test findCSSfindCSSxjQueryDomQuerycssQuery
13 / 04 / 00 / 02 / 00 / 4
W / FW / FW / FW / FW / F
*12.6ms0ms90.6ms12.4ms56.4ms
body0ms0ms0ms0ms6ms
body div6.2ms22ms24.8ms3ms31.2ms
div6ms0ms28ms3ms31ms
div div div9.2ms118.8ms450.2ms81.4msFAIL
div div9.4ms72ms237.8ms28.2msFAIL
.dialog6.2ms34.4ms31.2ms15.6ms72ms
div.dialog3.2ms18.6ms15.8ms9.4ms46.6ms
div .dialog9.2ms237.6ms225ms53msFAIL
#speech50ms0ms0ms0ms65.6ms
div#speech50ms0ms0ms0ms34.4ms
div #speech53ms234.2ms115.8ms34.4msFAIL
div > div6ms90.6ms84.2ms37.6ms131.2ms
div.scene div.dialog6.2ms46.8ms31.2ms15.8ms65.8ms
div#scene1.scene div.dialog div6.2ms56.2ms53.4ms15.8ms87.6ms
#scene1 #speech10ms28.2ms6.2ms0ms97ms
body > div.dialog div#speech50ms31ms12.4ms12.4ms37.6ms
body > div.dialog div:nth-child(even)50.2ms47ms559.4ms193.8ms1543.8ms
body > div.dialog div:nth-child(odd)50ms46.8ms549.8ms193.8ms1534.4ms
body > div.dialog div:nth-child(1)43.8ms50ms37.4ms28.2ms1059.2ms
body > div.dialog div:first-child6.2ms31ms37.6ms15.6ms50ms
div[@id*="speech"]6.2ms31ms40.6ms21.8ms43.8ms
body > div.dialog div:last-child6.2ms31.2ms37.4ms22ms53.4ms

Opera

Run? Test findCSS findCSSx jQuery DomQuery cssQuery
8 / 0 1 / 0 0 / 0 5 / 0 0 / 4
W / F W / F W / F W / F W / F
* 3.2ms 0ms 106.2ms 3ms 9.2ms
body 0ms 0ms 0ms 0ms 0ms
body div 0ms 22ms 31ms 3ms 3ms
div 0ms 0ms 31.2ms 0ms 3ms
div div div 6.2ms 93.6ms 290.8ms 18.6ms FAIL
div div 0ms 68.6ms 172ms 18.6ms FAIL
.dialog 3ms 6.2ms 15.6ms 3ms 12.4ms
div.dialog 0ms 3ms 9.4ms 0ms 6.2ms
div .dialog 6ms 156.4ms 47ms 15.6ms FAIL
#speech5 0ms 0ms 0ms 0ms 6.2ms
div#speech5 0ms 0ms 0ms 0ms 3ms
div #speech5 0ms 159.4ms 22ms 9.4ms FAIL
div > div 0ms 31.2ms 47ms 6ms 15.6ms
div.scene div.dialog 3ms 28.2ms 12.6ms 6.2ms 15.8ms
div#scene1.scene div.dialog div 0ms 34.4ms 31.2ms 6.2ms 15.8ms
#scene1 #speech1 0ms 21.8ms 0ms 0ms 12.4ms
body > div.dialog div#speech5 0ms 25ms 3ms 0ms 3ms
body > div.dialog div:nth-child(even) 47ms 46.8ms 59.2ms 15.6ms 197ms
body > div.dialog div:nth-child(odd) 47ms 49.8ms 59.4ms 12.6ms 199.8ms
body > div.dialog div:nth-child(1) 31.2ms 34.4ms 9.4ms 3ms 140.6ms
body > div.dialog div:first-child 6ms 25ms 9.2ms 0ms 15.6ms
div[@id*="speech"] 6.2ms 15.6ms 15.6ms 3ms 6.2ms
body > div.dialog div:last-child 3ms 28ms 9.4ms 3.2ms 9.4ms

Internet Explorer

Run?TestfindCSSfindCSSxjQueryDomQuerycssQuery
0 / 00 / 00 / 018 / 00 / 5
W / FW / FW / FW / FW / F
*0ms0ms375ms12.4msFAIL
body0ms0ms0ms0ms0ms
body div93.8ms96.8ms109.4ms6.2ms15.6ms
div0ms0ms109.4ms3.2ms15.6ms
div div div447ms453ms518.6ms62.4msFAIL
div div284.4ms284.4ms362.4ms31.2msFAIL
.dialog109.2ms125ms31.2ms12.4ms34.4ms
div.dialog34.4ms34.4ms18.8ms6.2ms15.8ms
div .dialog659.4ms722ms137.4ms37.4msFAIL
#speech50ms0ms0ms0ms0ms
div#speech50ms0ms0ms0ms15.6ms
div #speech5668.8ms731.2ms81.6ms31.2msFAIL
div > div178ms184.2ms137.4ms31ms343.4ms
div.scene div.dialog134.4ms134.4ms31.2ms15.4ms31.2ms
div#scene1.scene div.dialog div171.8ms172ms94ms15.6ms47ms
#scene1 #speech197ms97ms9.4ms0ms15.6ms
body > div.dialog div#speech596.8ms96.8ms12.4ms9.4ms24.8ms
body > div.dialog div:nth-child(even)306.2ms303.2ms212.4ms125ms824.8ms
body > div.dialog div:nth-child(odd)306.2ms303ms228ms125ms825ms
body > div.dialog div:nth-child(1)125ms125ms28ms18.8ms593.6ms
body > div.dialog div:first-child112.6ms109.4ms28ms15.6ms31.2ms
div[@id*="speech"]46.8ms47ms31.2ms12.4ms22ms
body > div.dialog div:last-child118.8ms122ms28.2ms15.6ms31.4ms

Conclusions

With these results, I can conclude that findCSS has a lot of potential. If I can get it working (much) faster in Internet Explorer it will be able to hold its own with the best of the CSS selector libraries. As it is, DomQuery is just plain amazing, solely for its speed in Internet Explorer. I will definitely be looking at DomQuery more closely to see how it pulls it off. Until then, findCSS will still be a useful tool in my future javascript projects


Warning: WARNING: Comments is not properly cleaning input params. in /home/freegam4/public_html/webtech/lib/classes/class.module.inc.php on line 1500

Comments

Add A Comment

What does ten plus three equal?
Your Name(*):
Email:
Comment(*):