Often times when coding one might pause to consider if one solution performs better than another — when they effectively do the same thing. When a toolkit is involved you might also have a trade-off between code brevity and plain old JavaScript to consider.
A helpful tool I use regularly is Fireunit, the Firebug add-on. It can be used for more than I’m going to show here, but for very quick tests to see how fast my code will run, I’ll pop open the console and try the code out there.
In this example, I’m just seeing which is faster at finding the head tag.
Here, I’m using dojo.query
dojo.query("head")[0];

What stands out is there are 8 individual calls, sure, each is tiny and only adds up to .5ms.
For comparison, we try the old fashioned way
document.getElementsByTagName("head")[0];

The native JavaScript is looking much faster, .144ms compared to .5ms.
Take note that all you need to do is pass fireunit.profile a function to test
fireunit.profile(function { ....do stuff....});
and the results are displayed directly in the console.
So what I learned was, using dojo.query for this very simple operation is slower than native code. I don’t doubt for a minute that a complex query would be faster than a plain JS alternative, but it did help make me conscious at least of testing code this way.
Another thing to highlight, if you run each test several times you see that after the first run, document.getElementsByTagName results get even better – over 20 times faster than the dojo.query code (which by the way doesn’t get faster in sequential runs).

