On 6/10/06, James M Snell <[EMAIL PROTECTED]> wrote:
FYI... a few weeks ago, Rob Yates added a performance enhancement to the
Abdera code that leads to a significant boost.  He discusses the
enhancement on his personal weblog @ http://robubu.com/?p=11

To give you an idea, he compared the performance of Rome and Abdera
parsing his own Atom feed and pulling out the titles and links of each
entry.
              Allocated bytes/CPU instructions
ROME:         2.64 MB/223 mil.
Abdera:       286 KB/30 mil.
Abdera+turbo: 66 KB/25 mil.

This seems very cool, something we should have an example of in the tree...

So I threw one together last night based on Rob's blog post.  I've
attached it, perhaps we can stick a version of it in examples once the
code is imported.

-garrett
import com.ibm.abdera.parser.Parser;
import com.ibm.abdera.parser.ParserOptions;

import com.ibm.abdera.model.Feed;
import com.ibm.abdera.model.Document;
import com.ibm.abdera.model.Entry;

import com.ibm.abdera.util.Constants;

import java.util.List;
import java.util.ArrayList;

import java.net.URL;
import java.net.MalformedURLException;

import java.io.InputStream;

import javax.xml.namespace.QName;

public class PrintTitles {
  public static void main(String args[]) {
    InputStream input;

    try {
      input = new URL(args[0]).openStream();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    ParserOptions opts = Parser.INSTANCE.getDefaultParserOptions();

    List<QName> elementsToParse = new ArrayList<QName>();

    elementsToParse.add(Constants.FEED);
    elementsToParse.add(Constants.ENTRY);
    elementsToParse.add(Constants.TITLE);

    opts.setParseFilter(elementsToParse);

    Document<Feed> doc;

    try { 
      doc = Parser.INSTANCE.parse(input, "", opts);
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    Feed feed = doc.getRoot();

    List<Entry> entries = feed.getEntries();

    for (Entry e : entries) {
      System.out.println(e.getTitle());
    }
  }
}

Reply via email to