Methods Summary |
---|
private java.io.InputStream | newInputStream()
return new ByteArrayInputStream(mXmlBytes);
|
private void | runExpatPullParser()
long start = System.currentTimeMillis();
XmlPullParser pullParser = Xml.newPullParser();
pullParser.setInput(newInputStream(), "UTF-8");
withPullParser(pullParser);
long elapsed = System.currentTimeMillis() - start;
Log.i(TAG, "expat pull: " + elapsed + "ms");
|
private void | runJavaPullParser()
XmlPullParser pullParser;
long start = System.currentTimeMillis();
pullParser = new KXmlParser();
pullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
pullParser.setInput(newInputStream(), "UTF-8");
withPullParser(pullParser);
long elapsed = System.currentTimeMillis() - start;
Log.i(TAG, "java pull parser: " + elapsed + "ms");
|
private void | runSax()
long start = System.currentTimeMillis();
Xml.parse(newInputStream(), Xml.Encoding.UTF_8, new DefaultHandler());
long elapsed = System.currentTimeMillis() - start;
Log.i(TAG, "expat SAX: " + elapsed + "ms");
|
public void | setUp()
super.setUp();
InputStream in = mContext.getResources().openRawResource(R.raw.youtube);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
mXmlBytes = out.toByteArray();
Log.i("***", "File size: " + (mXmlBytes.length / 1024) + "k");
|
public void | testPerformance()
// try {
// Debug.startMethodTracing("expat3");
// for (int i = 0; i < 1; i++) {
runJavaPullParser();
runSax();
runExpatPullParser();
// }
// } finally {
// Debug.stopMethodTracing();
// }
|
private static void | withPullParser(org.xmlpull.v1.XmlPullParser pullParser)
int eventType = pullParser.next();
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
pullParser.getName();
// int nattrs = pullParser.getAttributeCount();
// for (int i = 0; i < nattrs; ++i) {
// pullParser.getAttributeName(i);
// pullParser.getAttributeValue(i);
// }
break;
case XmlPullParser.END_TAG:
pullParser.getName();
break;
case XmlPullParser.TEXT:
pullParser.getText();
break;
}
eventType = pullParser.next();
}
|