Backstory: Some [Unicode code points are invalid in XML][invalid]; specifically, we want to filter the code points (hex) 0-8, b-c, and e-1f. Qt4's QXmlStreamWriter() makes no attempt to filter these codepoints in the documents it writes.
So, here's our baseline, with the same benchmark we'll use later (big.gpx is a giant 142 MB file, and GPX is an XML-based format):
./gpsbabel -i gpx -f big.gpx [-o gpx -F /dev/null] (x5)
17.2 user, 4.8 system, 22.1 total
In [GPSBabel][], we already subclass QXmlStreamWriter to add other convenience methods. So our initial attempt to filter bad characters was simply to interpose on all methods that take potentially unfiltered inputs (writeAttribute(), writeTextElement(), ...) and apply a QString::replace() substitution with a QRegExp.