Sunday, April 22, 2012

DOM vs SAX on Android

It is well documented that when working with XML on an Android device, SAX is preferable over DOM. For MyExpenses, for importing categories from an XML file, I had ignored this advice, since originally it was planned to import a limited number of small files provided with the app. But later users got the possibility to provide their own file, and it was no longer possible to exclude the case of potentially large files being provided as input.
Having implemented the import based on the SAX parser now, using Androids infrastructure for unit testing, I could easily compare the two implementations through this UnitTest, and come up with a measurement of how they perform when confronted with large files. The table lists the time the test needs to run when parsing the files with SAX or DOM on a Google Nexus S:

FileSize SAX DOM
1M 0,755 4,934
2M 1,475 8,335
4M 3,019 19,347
6M 4,756 OutOfMemoryError

No comments:

Post a Comment