Two observations on performance implementing a class derived
from DefaultHandler:
1. If you use a large conditional for handling different tags, you
should do the comparisons in the order of most likely to be seen.
element distribution: Tag1 (10%); Tag2 (70%); Tag3 (20%)
Then:
void startElement(...)
{
if ( DOMString("Tag2").equals(localname) )
; // do something
else if ( DOMString("Tag3").equals(localname) )
; // do something
else if ( DOMString("Tag1").equals(localname) )
; // do something
}
In my application (with 18 tags), this made about a 3 X performance
increase.
Also, it should save string comparisons if all the tags were distinct
by their first character, but I don't seriously recommend this.
2. It appears that it is very expensive to do a DOMString("MyTag").
Basically don't ever do this:
void startElement(...)
{
if ( DOMString("MyTag").equals(localname) )
; // do something
}
Instead, do this:
void startElement(...)
{
static const DOMString cDOMStringMyTag("MyTag");
if ( cDOMStringMyTag.equals(localname) )
; // do something
}
In my application this caused about a 7 X performance increase on
top of the previous 3 X increase. I went from reading 100K elements
in 240 seconds to about 11 seconds.
Can anyone offer any comments on further accelerating my parsing?
Thanks,
Dee Jay
+-----------------------------+------------------+-----------------------+
| Founding Partner | Software Engineer| Dee Jay Randall, B.Sc.|
| Circular Reasoning | Accrue Software | M.Sc. Student, CS |
| [EMAIL PROTECTED]| www.accrue.com | ICQ # 43551676 |
+-----------------------------+------------------+-----------------------+
What is the average rank of every song ever written? 42 -- www.launch.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]