Performance Tip 10 - Keep Your expando Off the Document

Microsoft's test is not an isolated test

The performance test by Microsoft is not an isolated test.

According to Microsoft, referencing a property to document is slower than referencing the same property on window.

The problem with their test case is that the reference chain to window is shorter than the reference chain to document. This exaggerates the benefit.

My test uses a reference chain of equal length for both, (window.window and window.document). This allows true isolation of the test. Since the difference in my test appeared negligible, I increased the iterations by a factor of 5 —5,000 iterations in my test vs. Microsoft's 1000 iterations.

Click the buttons to see the difference in performance.

Test

 

 

My Results

Browser fast() slow()
Mozilla 1.3/ G3 134 milliseconds 104 milliseconds
IE 5.2.2/ G3 1815 milliseconds 1127 milliseconds
Safari Beta/ G3 287 milliseconds 260 milliseconds

Discussion

Though the Microsoft test is not isolated, Microsoft is correct in their advice: Keep your expando properties off document! The results here confirm that document lookups take longer than window lookups.