When all you have is a hammer, perhaps you should contemplate acquiring a table saw
February 6th, 2007 by Leons PetrazickisI had a an application that parsed an XML document and transformed it into a dojo.widget.Tree. This is how long it took with documents sized 15k, 34k, and 93k:
| IE6 | IE7 | Firefox2 | Opera9 | |
| 15k | 24 | 6 | 11 | 6 |
| 34k | 69 | 11 | 21 | 21 |
| 93k | 157 | 124 |
“Hmm,” I thought. “I don’t really need it to be collapsible or fancy. What if I replace the tree with a sequence of nbsp-indented lines and put that in via innerHTML?”
| IE6 | IE7 | Firefox2 | Opera9 | |
| 15k | 5 | 6 | 4 | 3 |
| 34k | 14 | 11 | 19 | 10 |
| 93k | ||||
Then Internet Explorer 6 doesn’t look as pathetic as it is.
But why am I doing data munging in Javascript? The browsers seem to very unhappy about loading 93 kilobytes of XML into DOM. Would it be faster in PHP?
| IE6 | IE7 | Firefox2 | Opera9 | |
| 15k | 1 | 1 | 1 | 1 |
| 34k | 1 | 1 | 1 | 1 |
| 93k | 5 | 2 | 6 | 3 |
Yes. Yes, it would. 80x faster, in fact.
In conclusion, currently PHP is far faster for hundreds of kilobytes of data munging. Javascript is optimized for something else entirely — page management. Use it to move data around, but don’t transform with it.
Posted in javascript, php |



