You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/02/02 01:40:21 UTC

svn commit: r149466 - jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestPerformance.java

Author: burton
Date: Tue Feb  1 16:40:19 2005
New Revision: 149466

URL: http://svn.apache.org/viewcvs?view=rev&rev=149466
Log:
benchmarks of SAX vs JDOM

Added:
    jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestPerformance.java

Added: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestPerformance.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestPerformance.java?view=auto&rev=149466
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestPerformance.java (added)
+++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestPerformance.java Tue Feb  1 16:40:19 2005
@@ -0,0 +1,161 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.feedparser.test;
+
+import java.applet.*;
+import java.util.*;
+import java.io.*;
+import java.net.*;
+import java.security.*;
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.apache.commons.feedparser.*;
+import org.apache.commons.feedparser.impl.*;
+import org.apache.commons.feedparser.network.*;
+
+import javax.xml.parsers.*;
+import org.xml.sax.*;
+import org.xml.sax.helpers.*;
+
+/**
+ *
+ * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
+ * @version $Id: TestAtom.java 149187 2005-01-30 23:54:29Z burton $
+ */
+public class TestPerformance {
+
+    static SAXParser parser = null;
+
+    public static void doTestSAX() throws Exception {
+
+        if ( parser == null ) {
+            parser = SAXParserFactory.newInstance().newSAXParser();
+
+            //need to enable SAX2 locals and namespace
+            parser.getXMLReader().setFeature( "http://xml.org/sax/features/namespaces", true );
+        }
+
+         org.apache.commons.feedparser.sax.RSSFeedParser handler =
+              new org.apache.commons.feedparser.sax.RSSFeedParser();
+
+         handler.listener = new DefaultFeedParserListener() {
+
+                 public void onChannel( FeedParserState state,
+                                        String title,
+                                        String link,
+                                        String description ) throws FeedParserException {
+
+//                      System.out.println( "onChannel: title: " + title );
+                    
+                 }
+
+                 public void onItem( FeedParserState state,
+                                     String title,
+                                     String link,
+                                     String description,
+                                     String permalink ) throws FeedParserException {
+
+//                     System.out.println( "onItem: title: " + title );
+                    
+                 }
+
+                 public void onItemEnd() throws FeedParserException {
+
+//                     System.out.println( "onItemEnd");
+
+                 }
+
+             };
+
+        String resource = "file:/home/burton/index.rss";
+        
+        ResourceRequest request = ResourceRequestFactory
+            .getResourceRequest( resource );
+
+        parser.parse( request.getInputStream(), handler );
+
+    }
+
+    public static void doTestDefault() throws Exception {
+
+        FeedParser parser = FeedParserFactory.newFeedParser();
+        FeedParserListener listener = new DefaultFeedParserListener() {};
+
+        String resource = "file:/home/burton/index.rss";
+        
+        ResourceRequest request = ResourceRequestFactory
+            .getResourceRequest( resource );
+        
+        parser.parse( listener,
+                      request.getInputStream(),
+                      resource );
+
+    }
+
+    public static void main( String[] args ) throws Exception {
+
+        TestPerformance test = new TestPerformance();
+        
+        //test.testGetWeblogLinkForResource();
+        //test.test1();
+
+        doTestMethod( "doTestSAX", TestPerformance.class, 100 );
+        doTestMethod( "doTestDefault", TestPerformance.class, 100 );
+        
+    }
+
+    public static void  doTestMethod( String name, Class clazz, int max ) throws Exception {
+
+        Method method = clazz.getMethod( name, null );
+
+        System.out.println( "Testing method: " + name );
+
+        long duration = 0;
+        
+        for ( int i = 0; i <= max; ++i ) {
+
+            long before = System.currentTimeMillis();
+            
+            method.invoke( null, null );
+
+            if ( i == 0 )
+                continue; //don't measure the first call
+
+            long after = System.currentTimeMillis();
+            duration += after-before;
+            
+        }
+
+        System.out.println( "----------------" );
+        System.out.println( "Total parse count: " + max );
+
+        System.out.println( "Total duration: " + duration + "  milliseconds" );
+
+        float totalAvgDuration = (float)duration / (float)max;
+
+        System.out.println( "Total avg duration: " + totalAvgDuration + "  milliseconds" );
+
+        float totalPerSecond = 1000 / totalAvgDuration;
+
+        System.out.println( "Total per second: " + totalPerSecond );
+
+    }
+
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org