You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2005/09/09 01:18:48 UTC
svn commit: r279672 [7/8] - in /xmlbeans/trunk/test/perf: ./ bin/ cases/
cases/xsd/ src/org/apache/xmlbeans/test/performance/jaxb/
src/org/apache/xmlbeans/test/performance/jaxb2/
src/org/apache/xmlbeans/test/performance/parsers/ src/org/apache/xmlbeans...
Modified: xmlbeans/trunk/test/perf/cases/xsd/purchase-order-jibxbinding.xml
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/cases/xsd/purchase-order-jibxbinding.xml?rev=279672&r1=279671&r2=279672&view=diff
==============================================================================
--- xmlbeans/trunk/test/perf/cases/xsd/purchase-order-jibxbinding.xml (original)
+++ xmlbeans/trunk/test/perf/cases/xsd/purchase-order-jibxbinding.xml Thu Sep 8 16:18:37 2005
@@ -1,22 +1,37 @@
-<binding>
- <mapping name="purchase-order" class="org.apache.xmlbeans.test.performance.jibx.binding.JibxPurchaseOrder">
- <namespace uri="http://openuri.org/easypo" default="elements"/>
- <structure name="customer" field="customer">
- <value name="name" field="name"/>
- <value name="address" field="address"/>
- </structure>
- <value name="date" field="date"/>
- <collection field="lineitems">
- <structure name="line-item" type="org.apache.xmlbeans.test.performance.jibx.binding.Lineitem">
- <value name="description" field="description"/>
- <value name="per-unit-ounces" field="perunitounces"/>
- <value name="price" field="price"/>
- <value name="quantity" field="quantity"/>
- </structure>
- </collection>
- <structure name="shipper" field="shipper">
- <value name="name" field="name"/>
- <value name="per-ounce-rate" field="perouncerate"/>
- </structure>
- </mapping>
-</binding>
+<!--
+ Copyright 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.
+-->
+<binding>
+ <mapping name="purchase-order" class="org.apache.xmlbeans.test.performance.jibx.binding.JibxPurchaseOrder">
+ <namespace uri="http://openuri.org/easypo" default="elements"/>
+ <structure name="customer" field="customer">
+ <value name="name" field="name"/>
+ <value name="address" field="address"/>
+ </structure>
+ <value name="date" field="date"/>
+ <collection field="lineitems">
+ <structure name="line-item" type="org.apache.xmlbeans.test.performance.jibx.binding.Lineitem">
+ <value name="description" field="description"/>
+ <value name="per-unit-ounces" field="perunitounces"/>
+ <value name="price" field="price"/>
+ <value name="quantity" field="quantity"/>
+ </structure>
+ </collection>
+ <structure name="shipper" field="shipper">
+ <value name="name" field="name"/>
+ <value name="per-ounce-rate" field="perouncerate"/>
+ </structure>
+ </mapping>
+</binding>
Modified: xmlbeans/trunk/test/perf/cases/xsd/purchase-order.xsd
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/cases/xsd/purchase-order.xsd?rev=279672&r1=279671&r2=279672&view=diff
==============================================================================
--- xmlbeans/trunk/test/perf/cases/xsd/purchase-order.xsd (original)
+++ xmlbeans/trunk/test/perf/cases/xsd/purchase-order.xsd Thu Sep 8 16:18:37 2005
@@ -1,36 +1,51 @@
-<xs:schema targetNamespace="http://openuri.org/easypo"
- xmlns:po="http://openuri.org/easypo"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified">
-
- <xs:element name="purchase-order">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="customer" type="po:customer"/>
- <xs:element name="date" type="xs:dateTime"/>
- <xs:element name="line-item" type="po:line-item" minOccurs="0" maxOccurs="unbounded"/>
- <xs:element name="shipper" type="po:shipper" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:complexType name="customer">
- <xs:sequence>
- <xs:element name="name" type="xs:string"/>
- <xs:element name="address" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="line-item">
- <xs:sequence>
- <xs:element name="description" type="xs:string"/>
- <xs:element name="per-unit-ounces" type="xs:decimal"/>
- <xs:element name="price" type="xs:double"/>
- <xs:element name="quantity" type="xs:int"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="shipper">
- <xs:sequence>
- <xs:element name="name" type="xs:string"/>
- <xs:element name="per-ounce-rate" type="xs:decimal"/>
- </xs:sequence>
- </xs:complexType>
-</xs:schema>
+<!--
+ Copyright 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.
+-->
+<xs:schema targetNamespace="http://openuri.org/easypo"
+ xmlns:po="http://openuri.org/easypo"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified">
+
+ <xs:element name="purchase-order">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="customer" type="po:customer"/>
+ <xs:element name="date" type="xs:dateTime"/>
+ <xs:element name="line-item" type="po:line-item" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="shipper" type="po:shipper" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:complexType name="customer">
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="address" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="line-item">
+ <xs:sequence>
+ <xs:element name="description" type="xs:string"/>
+ <xs:element name="per-unit-ounces" type="xs:decimal"/>
+ <xs:element name="price" type="xs:double"/>
+ <xs:element name="quantity" type="xs:int"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="shipper">
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="per-ounce-rate" type="xs:decimal"/>
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>
Modified: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb/POGetCustNameJaxb.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb/POGetCustNameJaxb.java?rev=279672&r1=279671&r2=279672&view=diff
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb/POGetCustNameJaxb.java (original)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb/POGetCustNameJaxb.java Thu Sep 8 16:18:37 2005
@@ -14,11 +14,7 @@
*/
package org.apache.xmlbeans.test.performance.jaxb;
-//import java.io.File;
-//import java.io.IOException;
-//import java.io.FileNotFoundException;
import java.io.CharArrayReader;
-//import java.lang.UnsupportedOperationException;
import org.apache.xmlbeans.test.performance.utils.PerfUtil;
import org.apache.xmlbeans.test.performance.utils.Constants;
@@ -27,7 +23,6 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
-//import java.util.List;
// from jaxb-generated schema jar(s)
import org.openuri.easypo.Customer;
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/NPrimTopDownJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/NPrimTopDownJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/NPrimTopDownJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/NPrimTopDownJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,88 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+// from jaxb-generated schema jar(s)
+import org.openuri.nonprimitives.jaxb2.NonPrimitives;
+import org.openuri.nonprimitives.jaxb2.Numerics;
+
+import javax.xml.datatype.DatatypeFactory;
+import java.util.GregorianCalendar;
+
+
+public class NPrimTopDownJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+
+ final int iterations = Constants.ITERATIONS;
+
+ NPrimTopDownJaxb2 test = new NPrimTopDownJaxb2();
+ long cputime;
+ int hash = 0;
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run() throws Exception
+ {
+ // create the doc
+ NonPrimitives nprim = new NonPrimitives();
+
+ // create and initialize the numerics
+ for(int i=0; i<Constants.PO_NUM_LINEITEMS; i++)
+ {
+ //NumericsImpl numerics = new NumericsImpl();
+ Numerics numerics = new Numerics();
+ numerics.setMydecimal(Constants.myBigDecimal);
+ numerics.setMyinteger(Constants.myPosBigInteger);
+ numerics.setMyneginteger(Constants.myNegBigInteger);
+ numerics.setMynonneginteger(Constants.myPosBigInteger);
+ numerics.setMynonposinteger(Constants.myNegBigInteger);
+ numerics.setMyposinteger(Constants.myPosBigInteger);
+ nprim.getNumerics().add(numerics);
+ }
+
+ // create and initialize the misc element
+ // Date required in javax.xml.datatype.XMLGregorianCalendar format
+ GregorianCalendar gdate = new GregorianCalendar();
+ nprim.setMydate(DatatypeFactory.newInstance().newXMLGregorianCalendar(Long.toString(gdate.getTimeInMillis())));
+ nprim.setMystring(Constants.myString);
+
+ // calculate a hash to return
+ int hash = ( nprim.getNumerics().size() ) * 17;
+ return hash;
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetCustNameJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetCustNameJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetCustNameJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetCustNameJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,104 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+import java.io.CharArrayReader;
+
+import org.apache.xmlbeans.test.performance.utils.PerfUtil;
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+// required by jaxb
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+// from jaxb-generated schema jar(s)
+import org.openuri.easypo.jaxb2.Customer;
+import org.openuri.easypo.jaxb2.PurchaseOrder;
+
+
+public class POGetCustNameJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+ final int iterations = Constants.GET_SET_ITERATIONS;
+ String filename;
+
+ if(args.length == 0){
+ filename = Constants.PO_INSTANCE_1;
+ }
+ else if(args[0].length() > 1){
+ filename = Constants.XSD_DIR+Constants.P+args[0];
+ }
+ else{
+ switch( Integer.parseInt(args[0]) )
+ {
+ case 1: filename = Constants.PO_INSTANCE_1; break;
+ case 2: filename = Constants.PO_INSTANCE_2; break;
+ case 3: filename = Constants.PO_INSTANCE_3; break;
+ case 4: filename = Constants.PO_INSTANCE_4; break;
+ case 5: filename = Constants.PO_INSTANCE_5; break;
+ case 6: filename = Constants.PO_INSTANCE_6; break;
+ case 7: filename = Constants.PO_INSTANCE_7; break;
+ default: filename = Constants.PO_INSTANCE_1; break;
+ }
+ }
+
+ POGetCustNameJaxb2 test = new POGetCustNameJaxb2();
+ PerfUtil util = new PerfUtil();
+ long cputime;
+ int hash = 0;
+
+ // get the xmlinstance
+ char[] chars = util.fileToChars(filename);
+
+ // create the xml source from the reader
+ StreamSource source = new StreamSource(new CharArrayReader(chars));
+ // unmarshall the xml instance
+ JAXBContext context = JAXBContext.newInstance("org.openuri.easypo.jaxb2");
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ //depricated - unmarshaller.setValidating(false);
+ PurchaseOrder po =
+ (PurchaseOrder) unmarshaller.unmarshal(source);
+ Customer customer = po.getCustomer();
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(customer);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(customer);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" filesize="+chars.length+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run(Customer p_customer) throws Exception
+ {
+ return p_customer.getName().length() * 17;
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetSetGetCustNameJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetSetGetCustNameJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetSetGetCustNameJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POGetSetGetCustNameJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,122 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+import java.io.CharArrayReader;
+
+import org.apache.xmlbeans.test.performance.utils.PerfUtil;
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+// required by jaxb
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+// from jaxb-generated schema jar(s)
+import org.openuri.easypo.jaxb2.Customer;
+import org.openuri.easypo.jaxb2.PurchaseOrder;
+import org.openuri.easypo.jaxb2.LineItem;
+
+
+public class POGetSetGetCustNameJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+ final int iterations = Constants.GET_SET_ITERATIONS;
+ String filename;
+ int stringSize = 0;
+ String stringToSet = "";
+
+ if(args.length == 0){
+ filename = Constants.PO_INSTANCE_1;
+ }
+ else if(args[0].length() > 1){
+ filename = Constants.XSD_DIR+Constants.P+args[0];
+ }
+ else{
+ switch( Integer.parseInt(args[0]) )
+ {
+ case 1: filename = Constants.PO_INSTANCE_1; break;
+ case 2: filename = Constants.PO_INSTANCE_2; break;
+ case 3: filename = Constants.PO_INSTANCE_3; break;
+ case 4: filename = Constants.PO_INSTANCE_4; break;
+ case 5: filename = Constants.PO_INSTANCE_5; break;
+ case 6: filename = Constants.PO_INSTANCE_6; break;
+ case 7: filename = Constants.PO_INSTANCE_7; break;
+ default: filename = Constants.PO_INSTANCE_1; break;
+ }
+ }
+
+ // the size of the string used is the second arg or default if not specified
+ if(args.length < 2)
+ {
+ stringSize = Constants.STRING_SIZE;
+ }
+ else
+ {
+ stringSize = Integer.parseInt(args[1]);
+ }
+
+ POGetSetGetCustNameJaxb2 test = new POGetSetGetCustNameJaxb2();
+ PerfUtil util = new PerfUtil();
+ long cputime;
+ int hash = 0;
+
+ // create the string to be used for the set
+ stringToSet = util.createString(stringSize);
+
+ // get the xmlinstance
+ char[] chars = util.fileToChars(filename);
+
+ // create the xml source from the reader
+ StreamSource source = new StreamSource(new CharArrayReader(chars));
+ // unmarshall the xml instance
+ JAXBContext context = JAXBContext.newInstance("org.openuri.easypo.jaxb2");
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ // depricated - unmarshaller.setValidating(false);
+ PurchaseOrder po =
+ (PurchaseOrder) unmarshaller.unmarshal(source);
+ Customer customer = po.getCustomer();
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(customer,stringToSet);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(customer,stringToSet);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" filesize="+chars.length+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run(Customer p_customer, String p_setval) throws Exception
+ {
+ p_customer.getName();
+ p_customer.setName(p_setval);
+ return p_customer.getName().length() * 17;
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadAllJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadAllJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadAllJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadAllJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,134 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+//import java.io.File;
+import java.io.CharArrayReader;
+
+import org.apache.xmlbeans.test.performance.utils.PerfUtil;
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+// required by jaxb
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+import java.util.Iterator;
+
+// from jaxb-generated schema jar(s)
+import org.openuri.easypo.jaxb2.PurchaseOrder;
+import org.openuri.easypo.jaxb2.Customer;
+import org.openuri.easypo.jaxb2.LineItem;
+import org.openuri.easypo.jaxb2.Shipper;
+
+
+public class POReadAllJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+ final int iterations = Constants.ITERATIONS;
+ String filename;
+
+ if(args.length == 0){
+ filename = Constants.PO_INSTANCE_1;
+ }
+ else if(args[0].length() > 1){
+ filename = Constants.XSD_DIR+Constants.P+args[0];
+ }
+ else{
+ switch( Integer.parseInt(args[0]) )
+ {
+ case 1: filename = Constants.PO_INSTANCE_1; break;
+ case 2: filename = Constants.PO_INSTANCE_2; break;
+ case 3: filename = Constants.PO_INSTANCE_3; break;
+ case 4: filename = Constants.PO_INSTANCE_4; break;
+ case 5: filename = Constants.PO_INSTANCE_5; break;
+ case 6: filename = Constants.PO_INSTANCE_6; break;
+ case 7: filename = Constants.PO_INSTANCE_7; break;
+ default: filename = Constants.PO_INSTANCE_1; break;
+ }
+ }
+
+ POReadAllJaxb2 test = new POReadAllJaxb2();
+ PerfUtil util = new PerfUtil();
+ long cputime;
+ int hash = 0;
+
+ // get the xmlinstance
+ char[] chars = util.fileToChars(filename);
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(reader);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(reader);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" filesize="+chars.length+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run(CharArrayReader reader) throws Exception
+ {
+ int iSumStrings = 0;
+ // create the xml source from the reader
+ StreamSource source = new StreamSource(reader);
+ // unmarshall the xml instance
+ JAXBContext context = JAXBContext.newInstance("org.openuri.easypo.jaxb2");
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ //depricated - unmarshaller.setValidating(false);
+ PurchaseOrder po =
+ (PurchaseOrder) unmarshaller.unmarshal(source);
+
+ // retreive the customer element
+ Customer customer = po.getCustomer();
+ iSumStrings += customer.getAddress().length();
+ iSumStrings += customer.getName().length();
+ // retreive the date
+ po.getDate();
+ // retrive the shipper element
+ po.getShipper().getName();
+ po.getShipper().getPerOunceRate();
+
+ // retreive all line items
+ Iterator it = po.getLineItem().iterator();
+ // sum the line item prices and get the other childs
+ float sum = 0;
+ while(it.hasNext()){
+ LineItem li = (LineItem) it.next();
+ iSumStrings += li.getDescription().length();
+ li.getPerUnitOunces();
+ li.getQuantity();
+ sum += li.getPrice();
+ }
+ // retreive the shipper element
+ Shipper shipper = po.getShipper();
+ iSumStrings += shipper.getName().length();
+ shipper.getPerOunceRate();
+
+ return iSumStrings;
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadOneJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadOneJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadOneJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POReadOneJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,106 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+import java.io.CharArrayReader;
+import org.apache.xmlbeans.test.performance.utils.PerfUtil;
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+// required by jaxb
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+// from jaxb-generated schema jar(s)
+import org.openuri.easypo.jaxb2.PurchaseOrder;
+import org.openuri.easypo.jaxb2.LineItem;
+
+
+public class POReadOneJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+ final int iterations = Constants.ITERATIONS;
+ String filename;
+
+ if(args.length == 0){
+ filename = Constants.PO_INSTANCE_1;
+ }
+ else if(args[0].length() > 1){
+ filename = Constants.XSD_DIR+Constants.P+args[0];
+ }
+ else{
+ switch( Integer.parseInt(args[0]) )
+ {
+ case 1: filename = Constants.PO_INSTANCE_1; break;
+ case 2: filename = Constants.PO_INSTANCE_2; break;
+ case 3: filename = Constants.PO_INSTANCE_3; break;
+ case 4: filename = Constants.PO_INSTANCE_4; break;
+ case 5: filename = Constants.PO_INSTANCE_5; break;
+ case 6: filename = Constants.PO_INSTANCE_6; break;
+ case 7: filename = Constants.PO_INSTANCE_7; break;
+ default: filename = Constants.PO_INSTANCE_1; break;
+ }
+ }
+
+ POReadOneJaxb2 test = new POReadOneJaxb2();
+ PerfUtil util = new PerfUtil();
+ long cputime;
+ int hash = 0;
+
+ // get the xmlinstance
+ char[] chars = util.fileToChars(filename);
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(reader);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ CharArrayReader reader = new CharArrayReader(chars);
+ hash += test.run(reader);
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" filesize="+chars.length+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run(CharArrayReader reader) throws Exception
+ {
+ // create the xml source from the reader
+ StreamSource source = new StreamSource(reader);
+ // unmarshall the xml instance
+ JAXBContext context = JAXBContext.newInstance("org.openuri.easypo.jaxb2");
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ //depricated - unmarshaller.setValidating(false);
+ PurchaseOrder po =
+ (PurchaseOrder) unmarshaller.unmarshal(source);
+
+ // retreive the first line item
+ LineItem lineitem = (LineItem) po.getLineItem().get(0);
+
+ // return the char length of the description
+ return lineitem.getDescription().length();
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,98 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+import java.util.GregorianCalendar;
+
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+// from jaxb-generated schema jar(s)
+import org.openuri.easypo.jaxb2.PurchaseOrder;
+import org.openuri.easypo.jaxb2.Customer;
+import org.openuri.easypo.jaxb2.LineItem;
+import org.openuri.easypo.jaxb2.Shipper;
+
+
+public class POTopDownJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+
+ final int iterations = Constants.ITERATIONS;
+
+ POTopDownJaxb2 test = new POTopDownJaxb2();
+ long cputime;
+ int hash = 0;
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run() throws Exception
+ {
+ // create the purchase order
+ PurchaseOrder po = new PurchaseOrder();
+
+ // create and initialize the customer
+ Customer customer = new Customer();
+ customer.setName(Constants.PO_CUSTOMER_NAME);
+ customer.setAddress(Constants.PO_CUSTOMER_ADDR);
+ po.setCustomer(customer);
+
+ // set the date
+ // Date required in javax.xml.datatype.XMLGregorianCalendar format
+ GregorianCalendar gdate = new GregorianCalendar();
+ po.setDate(javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(Long.toString(gdate.getTimeInMillis())));
+
+ // create and initialize the line item array
+ for(int i=0; i<Constants.PO_NUM_LINEITEMS; i++)
+ {
+ LineItem li = new LineItem();
+ li.setDescription(Constants.PO_LI_DESC);
+ li.setPerUnitOunces(Constants.PO_LI_PUO);
+ li.setPrice(Constants.PO_LI_PRICE);
+ li.setQuantity(Constants.PO_LI_QUANTITY);
+ po.getLineItem().add(li);
+ }
+
+ // create and initialize the shipper
+ Shipper shipper = new Shipper();
+ shipper.setName(Constants.PO_SHIPPER_NAME);
+ shipper.setPerOunceRate(Constants.PO_SHIPPER_POR);
+ po.setShipper(shipper);
+
+ // calculate a hash to return
+ int hash = ( po.getLineItem().size() ) * 17;
+ return hash;
+
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownSaveJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownSaveJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownSaveJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/POTopDownSaveJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,109 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+import java.util.GregorianCalendar;
+import java.io.StringWriter;
+
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+// required by jaxb
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+// from jaxb-generated schema jar(s)
+import org.openuri.easypo.jaxb2.PurchaseOrder;
+import org.openuri.easypo.jaxb2.Customer;
+import org.openuri.easypo.jaxb2.LineItem;
+import org.openuri.easypo.jaxb2.Shipper;
+
+
+public class POTopDownSaveJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+
+ final int iterations = Constants.ITERATIONS;
+
+ POTopDownSaveJaxb2 test = new POTopDownSaveJaxb2();
+ long cputime;
+ int hash = 0;
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run() throws Exception
+ {
+ // create the purchase order
+ PurchaseOrder po = new PurchaseOrder();
+
+ // create and initialize the customer
+ Customer customer = new Customer();
+ customer.setName(Constants.PO_CUSTOMER_NAME);
+ customer.setAddress(Constants.PO_CUSTOMER_ADDR);
+ po.setCustomer(customer);
+
+ // set the date
+ // Date required in javax.xml.datatype.XMLGregorianCalendar format
+ GregorianCalendar gdate = new GregorianCalendar();
+ po.setDate(javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(Long.toString(gdate.getTimeInMillis())));
+
+ // create and initialize the line item array
+ for(int i=0; i<Constants.PO_NUM_LINEITEMS; i++)
+ {
+ LineItem li = new LineItem();
+ li.setDescription(Constants.PO_LI_DESC);
+ li.setPerUnitOunces(Constants.PO_LI_PUO);
+ li.setPrice(Constants.PO_LI_PRICE);
+ li.setQuantity(Constants.PO_LI_QUANTITY);
+ po.getLineItem().add(li);
+ }
+
+ // create and initialize the shipper
+ Shipper shipper = new Shipper();
+ shipper.setName(Constants.PO_SHIPPER_NAME);
+ shipper.setPerOunceRate(Constants.PO_SHIPPER_POR);
+ po.setShipper(shipper);
+
+ // grab the instance that was constructed
+ JAXBContext context = JAXBContext.newInstance("org.openuri.easypo.jaxb2");
+ Marshaller marshaller = context.createMarshaller();
+ StringWriter writer = new StringWriter();
+ marshaller.marshal(po,writer);
+
+ // calculate a hash to return
+ int hash = ( po.getLineItem().size() ) * 17;
+ return hash;
+
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/PrimTopDownJaxb2.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/PrimTopDownJaxb2.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/PrimTopDownJaxb2.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/jaxb2/PrimTopDownJaxb2.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,87 @@
+/* Copyright 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.xmlbeans.test.performance.jaxb2;
+
+import org.apache.xmlbeans.test.performance.utils.Constants;
+
+
+// from jaxb-generated schema jar(s)
+import org.openuri.primitives.jaxb2.Primitives;
+import org.openuri.primitives.jaxb2.Numerics;
+import org.openuri.primitives.jaxb2.Misc;
+
+
+public class PrimTopDownJaxb2
+{
+ public static void main(String[] args) throws Exception
+ {
+ final int iterations = Constants.ITERATIONS;
+
+ PrimTopDownJaxb2 test = new PrimTopDownJaxb2();
+ long cputime;
+ int hash = 0;
+
+ // warm up the vm
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // run it again for the real measurement
+ cputime = System.currentTimeMillis();
+ for(int i=0; i<iterations; i++){
+ hash += test.run();
+ }
+ cputime = System.currentTimeMillis() - cputime;
+
+ // print the results
+ // Class.getSimpleName() is only provided in jdk1.5, so have to trim package name off test name for logging to support 1.4
+ System.out.print(Constants.DELIM+test.getClass().getName().substring(test.getClass().getName().lastIndexOf('.')+1)+" ");
+ System.out.print("hash "+hash+" ");
+ System.out.print("time "+cputime+"\n");
+ }
+
+ private int run() throws Exception
+ {
+ // create the doc
+ Primitives prim = new Primitives();
+
+ // create and initialize the numerics
+ for(int i=0; i<Constants.PO_NUM_LINEITEMS; i++)
+ {
+ Numerics numerics = new Numerics();
+ numerics.setMybyte(Constants.myByte);
+ numerics.setMyint(Constants.myInt);
+ numerics.setMylong(Constants.myLong);
+ numerics.setMyshort(Constants.myShort);
+ numerics.setMyhexbin(Constants.myHexbin);
+ numerics.setMydouble(Constants.myDouble);
+ numerics.setMyfloat(Constants.myFloat);
+ prim.getNumerics().add(numerics);
+ }
+
+ // create and initialize the misc element
+ Misc misc = new Misc();
+ misc.setMybool(Constants.myBool);
+ prim.setMisc(misc);
+
+ // calculate a hash to return
+ int hash = ( prim.getNumerics().size() ) * 17;
+ return hash;
+
+
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/BaseSaxPerfTest.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/BaseSaxPerfTest.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/BaseSaxPerfTest.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/BaseSaxPerfTest.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,302 @@
+/* Copyright 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.xmlbeans.test.performance.parsers;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.ext.LexicalHandler;
+
+import javax.xml.namespace.QName;
+import java.util.Collection;
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ * Date: Aug 8, 2005
+ */
+public class BaseSaxPerfTest
+{
+ public static class CopyAndStoreDataSaxHandler
+ extends DoNothingSaxHandler
+ implements ContentHandler, LexicalHandler, ErrorHandler
+ {
+ private Collection _store;
+
+ CopyAndStoreDataSaxHandler(XMLReader r, Collection c)
+ {
+ super(r);
+ if (c==null)
+ throw new IllegalArgumentException();
+ _store = c;
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException
+ {
+// System.out.println(" PM: " + prefix + "=" + uri);
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException
+ {
+ QName elName = new QName(uri, localName, qName);
+ _store.add(elName);
+// System.out.println(" SE: " + elName);
+ int l = atts.getLength();
+ for (int i = 0; i < l; i++)
+ {
+ QName attName = new QName(atts.getURI(i), atts.getLocalName(i), atts.getQName(i));
+ String val = atts.getValue(i);
+ _store.add(attName);
+ _store.add(val);
+// System.out.println(" AT: " + attName + "='" + val + "' " + atts.getType(i));
+ }
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException
+ {
+ QName elName = new QName(uri, localName, qName);
+ _store.add(elName);
+// System.out.println(" EE: " + elName);
+ }
+
+ public void characters(char ch[], int start, int length)
+ throws SAXException
+ {
+ char[] buf = new char[length];
+ System.arraycopy(ch, start, buf, 0, length);
+ _store.add(buf);
+// System.out.println(" CH: '" + new String(buf).replace("\n", "\\n") + "'");
+ }
+
+ public void ignorableWhitespace(char ch[], int start, int length)
+ throws SAXException
+ {
+ char[] buf = new char[length];
+ System.arraycopy(ch, start, buf, 0, length);
+ _store.add(buf);
+// System.out.println(" SP: '" + new String(buf).replace("\n", "\\n") + "'");
+ }
+
+ public void comment(char ch[], int start, int length)
+ throws SAXException
+ {
+ char[] buf = new char[length];
+ System.arraycopy(ch, start, buf, 0, length);
+ _store.add(buf);
+ }
+ }
+
+ public static class CopyDataSaxHandler extends DoNothingSaxHandler
+ implements ContentHandler, LexicalHandler, ErrorHandler
+ {
+ CopyDataSaxHandler(XMLReader r)
+ {
+ super(r);
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException
+ {
+// System.out.println(" PM: " + prefix + "=" + uri);
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException
+ {
+ QName elName = new QName(uri, localName, qName);
+// System.out.println(" SE: " + elName);
+ int l = atts.getLength();
+ for (int i = 0; i < l; i++)
+ {
+ QName attName = new QName(atts.getURI(i), atts.getLocalName(i), atts.getQName(i));
+ String val = atts.getValue(i);
+// System.out.println(" AT: " + attName + "='" + val + "' " + atts.getType(i));
+ }
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException
+ {
+ QName elName = new QName(uri, localName, qName);
+// System.out.println(" EE: " + elName);
+ }
+
+ public void characters(char ch[], int start, int length)
+ throws SAXException
+ {
+ char[] buf = new char[length];
+ System.arraycopy(ch, start, buf, 0, length);
+// System.out.println(" CH: '" + new String(buf).replace("\n", "\\n") + "'");
+ }
+
+ public void ignorableWhitespace(char ch[], int start, int length)
+ throws SAXException
+ {
+ char[] buf = new char[length];
+ System.arraycopy(ch, start, buf, 0, length);
+// System.out.println(" SP: '" + new String(buf).replace("\n", "\\n") + "'");
+ }
+
+ public void comment(char ch[], int start, int length)
+ throws SAXException
+ {
+ char[] buf = new char[length];
+ System.arraycopy(ch, start, buf, 0, length);
+ }
+ }
+
+ public static class DoNothingSaxHandler
+ implements ContentHandler, LexicalHandler, ErrorHandler
+ {
+ private XMLReader _xr;
+
+ DoNothingSaxHandler(XMLReader r)
+ {
+ _xr = r;
+
+ try
+ {
+ _xr.setFeature(
+ "http://xml.org/sax/features/namespace-prefixes", true);
+ _xr.setFeature("http://xml.org/sax/features/namespaces", true);
+ _xr.setFeature("http://xml.org/sax/features/validation", false);
+ _xr.setProperty(
+ "http://xml.org/sax/properties/lexical-handler", this);
+ _xr.setContentHandler(this);
+ _xr.setErrorHandler(this);
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void setDocumentLocator(Locator locator)
+ {
+ }
+
+ public void startDocument()
+ throws SAXException
+ {
+ }
+
+ public void endDocument()
+ throws SAXException
+ {
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException
+ {
+// System.out.println(" PM: " + prefix + "=" + uri);
+ }
+
+ public void endPrefixMapping(String prefix)
+ throws SAXException
+ {
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException
+ {
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException
+ {
+ }
+
+ public void characters(char ch[], int start, int length)
+ throws SAXException
+ {
+ }
+
+ public void ignorableWhitespace(char ch[], int start, int length)
+ throws SAXException
+ {
+ }
+
+ public void processingInstruction(String target, String data)
+ throws SAXException
+ {
+ }
+
+ public void skippedEntity(String name)
+ throws SAXException
+ {
+ }
+
+ public void startDTD(String name, String publicId, String systemId)
+ throws SAXException
+ {
+ }
+
+ public void endDTD()
+ throws SAXException
+ {
+ }
+
+ public void startEntity(String name)
+ throws SAXException
+ {
+ }
+
+ public void endEntity(String name)
+ throws SAXException
+ {
+ }
+
+ public void startCDATA()
+ throws SAXException
+ {
+// System.out.println("CDATA start");
+ }
+
+ public void endCDATA()
+ throws SAXException
+ {
+// System.out.println("CDATA start");
+ }
+
+ public void comment(char ch[], int start, int length)
+ throws SAXException
+ {
+ }
+
+ public void warning(SAXParseException exception)
+ throws SAXException
+ {
+ exception.printStackTrace(System.out);
+ }
+
+ public void error(SAXParseException exception)
+ throws SAXException
+ {
+ exception.printStackTrace(System.out);
+ }
+
+ public void fatalError(SAXParseException exception)
+ throws SAXException
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/DefaultSaxParserPerfTests.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/DefaultSaxParserPerfTests.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/DefaultSaxParserPerfTests.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/DefaultSaxParserPerfTests.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,84 @@
+/* Copyright 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.xmlbeans.test.performance.parsers;
+
+import org.xml.sax.XMLReader;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.FileInputStream;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ * Date: Jul 18, 2005
+ */
+public class DefaultSaxParserPerfTests
+{
+ static XMLReader defaultJDKParser;
+ static
+ {
+ try
+ {
+ defaultJDKParser = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+ }
+ catch (SAXException e)
+ {
+ e.printStackTrace();
+ }
+ catch (ParserConfigurationException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public static class DoNothingParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ new BaseSaxPerfTest.DoNothingSaxHandler(defaultJDKParser);
+ defaultJDKParser.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+
+ public static class CopyDataParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ new BaseSaxPerfTest.CopyDataSaxHandler(defaultJDKParser);
+ defaultJDKParser.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+
+ public static class CopyAndStoreDataParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ Collection store = new ArrayList();
+ new BaseSaxPerfTest.CopyAndStoreDataSaxHandler(defaultJDKParser, store);
+ defaultJDKParser.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Jaxb2Tests.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Jaxb2Tests.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Jaxb2Tests.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Jaxb2Tests.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,231 @@
+/* Copyright 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.xmlbeans.test.performance.parsers;
+
+import perf.po.Customer;
+import perf.po.LineItem;
+import perf.po.PurchaseOrder;
+import perf.po.Shipper;
+
+
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.math.BigDecimal;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ * Date: Aug 24, 2005
+ */
+public class Jaxb2Tests
+{
+ public static class LoadOnly
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws Exception
+ {
+ JAXBContext jc = JAXBContext.newInstance("perf.po");
+
+ // create an Unmarshaller
+ Unmarshaller u = jc.createUnmarshaller();
+
+ // unmarshal a po instance document into a tree of Java content
+ // objects composed of classes from the primer.po package.
+
+ //JAXBElement<?> poElement = (JAXBElement<?>) u.unmarshal(new FileInputStream(path + file));
+ //PurchaseOrder po = (PurchaseOrder) poElement.getValue();
+
+ perf.po.PurchaseOrder po = (perf.po.PurchaseOrder) u.unmarshal(new FileInputStream(file));
+ }
+ }
+
+ public static class LoadAndTraverse
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws Exception
+ {
+ JAXBContext jc = JAXBContext.newInstance("perf.po");
+
+ // create an Unmarshaller
+ Unmarshaller u = jc.createUnmarshaller();
+
+ // unmarshal a po instance document into a tree of Java content
+ // objects composed of classes from the primer.po package.
+
+ //JAXBElement<?> poElement = (JAXBElement<?>) u.unmarshal(new FileInputStream(path + file));
+ //PurchaseOrder po = (PurchaseOrder) poElement.getValue();
+
+ perf.po.PurchaseOrder po = (perf.po.PurchaseOrder) u.unmarshal(new FileInputStream(file));
+
+ //System.out.println("Cust name: " + po.getCustomer().getName());
+ //System.out.println(" address: " + po.getCustomer().getAddress());
+ //System.out.println("Date: " + po.getDate().toXMLFormat());
+ //System.out.println("Shipper name: " + po.getShipper().getName());
+ //System.out.println(" perOunceRate: " + po.getShipper().getPerOunceRate());
+ Iterator it = po.getLineItem().iterator();
+ while (it.hasNext())
+ {
+ LineItem lineItem = (LineItem) it.next();
+
+ double price = lineItem.getPrice();
+ int quantity = lineItem.getQuantity();
+ BigDecimal perUnitOunces = lineItem.getPerUnitOunces();
+ String description = lineItem.getDescription();
+
+ //System.out.println(" Line item: " + price + " " + quantity + " " + perUnitOunces + " " + description);
+ }
+ }
+ }
+
+ public static class CreateOnly
+ extends Utils.ParseFile
+ {
+ public void execute(String numberOfLineItems)
+ throws Exception
+ {
+ perf.po.PurchaseOrder po = new perf.po.PurchaseOrder();
+ Shipper shipper = new Shipper();
+ po.setShipper(shipper);
+
+ shipper.setPerOunceRate(new BigDecimal(0.744325345));
+ shipper.setName("ZipShip: twenty four characters");
+
+ List lineItems = po.getLineItem();
+ int liNo = Integer.parseInt(numberOfLineItems);
+ for(int i = 0; i<liNo; i++)
+ {
+ LineItem lineItem = new LineItem();
+ lineItems.add(lineItem);
+ lineItem.setQuantity(2);
+ lineItem.setPrice(21.7945342);
+ lineItem.setPerUnitOunces(new BigDecimal(5));
+ lineItem.setDescription("Fischer Black and the Revolutionary Idea of Finance");
+ }
+
+ Customer cust = new Customer();
+ po.setCustomer(cust);
+ cust.setAddress("12314 Murkyloshevichy, Anytown, PA");
+ cust.setName("Gladys Kravitz Steve Kilisky, Senior Product Manager, AdobeEffects");
+
+ po.setDate(javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar("2003-01-07T14:16:00-05:00"));
+
+ //System.out.println("CreateOnly: " + poDoc);
+
+ }
+ }
+
+ public static class CreateAndSave1
+ extends Utils.ParseFile
+ {
+ public void execute(String numberOfLineItems)
+ throws Exception
+ {
+ PurchaseOrder po = new PurchaseOrder();
+
+ Shipper shipper = new Shipper();
+ po.setShipper(shipper);
+
+ shipper.setPerOunceRate(new BigDecimal(0.744325345));
+ shipper.setName("ZipShip: twenty four characters");
+
+ List lineItems = po.getLineItem();
+ int liNo = Integer.parseInt(numberOfLineItems);
+ for(int i = 0; i<liNo; i++)
+ {
+ LineItem lineItem = new LineItem();
+ lineItems.add(lineItem);
+ lineItem.setQuantity(2);
+ lineItem.setPrice(21.7945342);
+ lineItem.setPerUnitOunces(new BigDecimal(5));
+ lineItem.setDescription("Fischer Black and the Revolutionary Idea of Finance");
+ }
+
+ Customer cust = new Customer();
+ po.setCustomer(cust);
+ cust.setAddress("12314 Murkyloshevichy, Anytown, PA");
+ cust.setName("Gladys Kravitz Steve Kilisky, Senior Product Manager, AdobeEffects");
+
+ po.setDate(javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar("2003-01-07T14:16:00-05:00"));
+
+ // Illustrate two methods to create JAXBContext for j2s binding.
+ // (1) by root classes newInstance(Class ...)
+ JAXBContext context1 = JAXBContext.newInstance(new Class[] {PurchaseOrder.class});
+ Marshaller m = context1.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ m.marshal(po, new Utils.NullOutputStream());
+
+ // (2) by package, requires jaxb.index file in package cardfile.
+ // newInstance(String packageNames)
+ //JAXBContext context2 = JAXBContext.newInstance("cardfile");
+ //Marshaller m2 = context1.createMarshaller();
+ //m2.marshal(getCard(), new FileOutputStream(f));
+ }
+ }
+
+ public static class CreateAndSave2
+ extends Utils.ParseFile
+ {
+ public void execute(String numberOfLineItems)
+ throws Exception
+ {
+ PurchaseOrder po = new PurchaseOrder();
+
+ Shipper shipper = new Shipper();
+ po.setShipper(shipper);
+
+ shipper.setPerOunceRate(new BigDecimal(0.744325345));
+ shipper.setName("ZipShip: twenty four characters");
+
+ List lineItems = po.getLineItem();
+ int liNo = Integer.parseInt(numberOfLineItems);
+ for(int i = 0; i<liNo; i++)
+ {
+ LineItem lineItem = new LineItem();
+ lineItems.add(lineItem);
+ lineItem.setQuantity(2);
+ lineItem.setPrice(21.7945342);
+ lineItem.setPerUnitOunces(new BigDecimal(5));
+ lineItem.setDescription("Fischer Black and the Revolutionary Idea of Finance");
+ }
+
+ Customer cust = new Customer();
+ po.setCustomer(cust);
+ cust.setAddress("12314 Murkyloshevichy, Anytown, PA");
+ cust.setName("Gladys Kravitz Steve Kilisky, Senior Product Manager, AdobeEffects");
+
+ po.setDate(javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar("2003-01-07T14:16:00-05:00"));
+
+ // Illustrate two methods to create JAXBContext for j2s binding.
+ // (1) by root classes newInstance(Class ...)
+ //JAXBContext context1 = JAXBContext.newInstance(PurchaseOrder.class);
+ //Marshaller m = context1.createMarshaller();
+ //m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ //m.marshal(po, new FileOutputStream(File.createTempFile("Perf", "JAXB2")));
+
+ // (2) by package, requires jaxb.index file in package cardfile.
+ // newInstance(String packageNames)
+ JAXBContext context2 = JAXBContext.newInstance("perf.po");
+ Marshaller m2 = context2.createMarshaller();
+ m2.marshal(po, new Utils.NullOutputStream());
+ }
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/PiccoloPerfTests.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/PiccoloPerfTests.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/PiccoloPerfTests.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/PiccoloPerfTests.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,67 @@
+/* Copyright 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.xmlbeans.test.performance.parsers;
+
+import org.xml.sax.XMLReader;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+
+import java.io.IOException;
+import java.io.FileInputStream;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ * Date: Jul 12, 2005
+ */
+public class PiccoloPerfTests
+{
+ static XMLReader picollo = new org.apache.xmlbeans.impl.piccolo.xml.Piccolo();
+
+ public static class DoNothingParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ new BaseSaxPerfTest.DoNothingSaxHandler(PiccoloPerfTests.picollo);
+ PiccoloPerfTests.picollo.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+
+ public static class CopyDataParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ new BaseSaxPerfTest.CopyDataSaxHandler(PiccoloPerfTests.picollo);
+ PiccoloPerfTests.picollo.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+
+ public static class CopyAndStoreDataParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ Collection store = new ArrayList();
+ new BaseSaxPerfTest.CopyAndStoreDataSaxHandler(PiccoloPerfTests.picollo, store);
+ PiccoloPerfTests.picollo.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Utils.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Utils.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Utils.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/Utils.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,133 @@
+/* Copyright 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.xmlbeans.test.performance.parsers;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.File;
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ * Date: Jul 12, 2005
+ */
+public class Utils
+{
+ public static final String P = File.separator;
+ public static final String INSTANCES_DIR = org.apache.xmlbeans.test.performance.utils.Constants.XML_DIR + P;
+
+ public static String file1k = INSTANCES_DIR + "purchase-order-1k.xml";
+ public static String file10k = INSTANCES_DIR + "purchase-order-10k.xml";
+ public static String file100k = INSTANCES_DIR + "purchase-order-100k.xml";
+ public static String file1M = INSTANCES_DIR + "purchase-order-1M.xml";
+ public static String file10M = INSTANCES_DIR + "purchase-order-10M.xml";
+
+ public static int TIME_THRESHHOLD_MS = 2000; // 2sec threshold time for a test
+ public static int COUNT_WARMING = 5;
+
+ public static String printTime(long time, int count)
+ {
+ if (time==0 || count==0)
+ throw new IllegalArgumentException("time=" + time + " count=" + 0);
+
+ String res = printDouble(((double)time)/count) + " ms/case ";
+
+
+ if (((double)time/(count*1000))>1)
+ res += printDouble((double)(time/(1000*count))) + " s/case (count: " + count + " in " + time + " ms)";
+ else if (((double)time/count)>1)
+ res += printDouble((double)time/count) + " ms/case (count: " + count + " in " + time + " ms)";
+ else
+ res += printDouble((double)(time*1000)/count) + " ns/case (count: " + count + " in " + time + " ms)";
+
+ return res;
+ }
+
+ public static String printDouble(double d)
+ {
+ if (d<0.1)
+ return "time " + (double)((int)(d*10000))/10000;
+
+ return "time " + (double)((int)(d*100))/100;
+ }
+
+ public static abstract class ParseFile
+ {
+ private boolean _failed = false;
+
+ public void run(String file)
+ throws Exception
+ {
+ preRun();
+ _failed = false;
+ try
+ {
+ long time = System.currentTimeMillis();
+ for (int i = 0; i < COUNT_WARMING; i++)
+ {
+ execute(file);
+ }
+ time = System.currentTimeMillis() - time;
+
+ double timeOfOneRun = time / COUNT_WARMING;
+ int count = time < 1 ? TIME_THRESHHOLD_MS :
+ timeOfOneRun > TIME_THRESHHOLD_MS ? 1 :
+ 1 + (int) (TIME_THRESHHOLD_MS / timeOfOneRun);
+ //System.out.println(" time: " + time + " for count_warming: " + COUNT_WARMING + " => count: " + count +
+ // " ver: " + count*timeOfOneRun + " ms");
+
+ time = System.currentTimeMillis();
+ for (int i = 0; i < count; i++)
+ {
+ execute(file);
+ }
+ time = System.currentTimeMillis() - time;
+
+ //System.out.println(" TEST: " + this.getClass().getName() + " " + printTime(time, count) + " " + file);
+ System.out.println("TEST: " + this.getClass().getName() + " file=" + file + " hash 000000 " + printTime(time, count) + " " );
+ }
+ catch(Exception e)
+ {
+ _failed = true;
+ System.out.println(" FAILED Test: " + this.getClass().getName() + " " + file);
+ e.printStackTrace(System.out);
+ }
+ finally
+ {
+ postRun();
+ }
+ }
+
+ public abstract void execute(String file)
+ throws Exception;
+
+ public void preRun() {}
+ public void postRun() {}
+
+ public boolean isFailed()
+ {
+ return _failed;
+ }
+ }
+
+ public static class NullOutputStream
+ extends OutputStream
+ {
+ public void write(int b)
+ throws IOException
+ {
+ // do nothing
+ }
+ }
+}
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XMLParsers.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XMLParsers.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XMLParsers.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XMLParsers.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,140 @@
+/* Copyright 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.xmlbeans.test.performance.parsers;
+
+import java.io.File;
+
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ * Date: Jul 11, 2005
+ */
+public class XMLParsers
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ runJaxb2Tests();
+ runXBTests();
+
+ runPiccoloTests();
+ runDefaultJDKParserTests();
+ runXercesSaxParserTests();
+ }
+
+ public static void runPiccoloTests()
+ throws Exception
+ {
+ Utils.ParseFile doNothingTest = new PiccoloPerfTests.DoNothingParseFile();
+ runAllFiles(doNothingTest);
+
+ Utils.ParseFile copyDataTest = new PiccoloPerfTests.CopyDataParseFile();
+ runAllFiles(copyDataTest);
+
+ Utils.ParseFile copyAndStoreDataTest = new PiccoloPerfTests.CopyAndStoreDataParseFile();
+ runAllFiles(copyAndStoreDataTest);
+ }
+
+ public static void runDefaultJDKParserTests()
+ throws Exception
+ {
+ Utils.ParseFile doNothingTest = new DefaultSaxParserPerfTests.DoNothingParseFile();
+ runAllFiles(doNothingTest);
+
+ Utils.ParseFile copyDataTest = new DefaultSaxParserPerfTests.CopyDataParseFile();
+ runAllFiles(copyDataTest);
+
+ Utils.ParseFile copyAndStoreDataTest = new DefaultSaxParserPerfTests.CopyAndStoreDataParseFile();
+ runAllFiles(copyAndStoreDataTest);
+ }
+
+ public static void runXercesSaxParserTests()
+ throws Exception
+ {
+ Utils.ParseFile doNothingTest = new XercesSaxParserPerfTests.DoNothingParseFile();
+ runAllFiles(doNothingTest);
+
+ Utils.ParseFile copyDataTest = new XercesSaxParserPerfTests.CopyDataParseFile();
+ runAllFiles(copyDataTest);
+
+ Utils.ParseFile copyAndStoreDataTest = new XercesSaxParserPerfTests.CopyAndStoreDataParseFile();
+ runAllFiles(copyAndStoreDataTest);
+ }
+
+ public static void runJaxb2Tests()
+ throws Exception
+ {
+ Utils.ParseFile loadOnly = new Jaxb2Tests.LoadOnly();
+ runAllFiles(loadOnly);
+
+ Utils.ParseFile loadAndTraverse = new Jaxb2Tests.LoadAndTraverse();
+ runAllFiles(loadAndTraverse);
+
+ Utils.ParseFile createonly = new Jaxb2Tests.CreateOnly();
+ runAllFiles2(createonly);
+
+ Utils.ParseFile createAndSave1 = new Jaxb2Tests.CreateAndSave1();
+ runAllFiles2(createAndSave1);
+
+ Utils.ParseFile createAndSave2 = new Jaxb2Tests.CreateAndSave2();
+ runAllFiles2(createAndSave2);
+ }
+
+ public static void runXBTests()
+ throws Exception
+ {
+ Utils.ParseFile loadOnly = new XmlBeansTests.LoadOnly();
+ runAllFiles(loadOnly);
+
+ Utils.ParseFile loadAndTraverseArray = new XmlBeansTests.LoadAndTraverseArray();
+ runAllFiles(loadAndTraverseArray);
+
+ Utils.ParseFile loadAndTraverseItem = new XmlBeansTests.LoadAndTraverseItem();
+ runAllFiles(loadAndTraverseItem);
+
+
+ Utils.ParseFile createOnly = new XmlBeansTests.CreateOnly();
+ runAllFiles2(createOnly);
+
+ Utils.ParseFile createAndSave = new XmlBeansTests.CreateAndSave();
+ runAllFiles2(createAndSave);
+ }
+
+ private static void runAllFiles(Utils.ParseFile parseTest)
+ throws Exception
+ {
+ parseTest.run(Utils.file1k);
+ parseTest.run(Utils.file1k);
+ parseTest.run(Utils.file10k);
+ parseTest.run(Utils.file100k);
+ parseTest.run(Utils.file1M);
+ parseTest.run(Utils.file10M);
+ }
+
+ private static void runAllFiles2(Utils.ParseFile parseTest)
+ throws Exception
+ {
+ parseTest.run("2");
+ parseTest.run("2");
+ parseTest.run("36");
+ parseTest.run("377");
+ parseTest.run("3863");
+ parseTest.run("38630");
+ }
+
+
+}
+
+
Added: xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XercesSaxParserPerfTests.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XercesSaxParserPerfTests.java?rev=279672&view=auto
==============================================================================
--- xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XercesSaxParserPerfTests.java (added)
+++ xmlbeans/trunk/test/perf/src/org/apache/xmlbeans/test/performance/parsers/XercesSaxParserPerfTests.java Thu Sep 8 16:18:37 2005
@@ -0,0 +1,84 @@
+/* Copyright 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.xmlbeans.test.performance.parsers;
+
+import org.xml.sax.XMLReader;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.FileInputStream;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * @author Cezar Andrei (cezar.andrei at bea.com)
+ * Date: Jul 18, 2005
+ */
+public class XercesSaxParserPerfTests
+{
+ static XMLReader _xercesSaxParser;
+ static
+ {
+ try
+ {
+ _xercesSaxParser = org.apache.xerces.jaxp.SAXParserFactoryImpl.newInstance().newSAXParser().getXMLReader();
+ System.out.println("Xerces SAX parser: " + _xercesSaxParser + " " + org.apache.xerces.impl.Version.getVersion());
+ }
+ catch (SAXException e)
+ {
+ e.printStackTrace();
+ }
+ catch (ParserConfigurationException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public static class DoNothingParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ new BaseSaxPerfTest.DoNothingSaxHandler(_xercesSaxParser);
+ _xercesSaxParser.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+
+ public static class CopyDataParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ new BaseSaxPerfTest.CopyDataSaxHandler(_xercesSaxParser);
+ _xercesSaxParser.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+
+ public static class CopyAndStoreDataParseFile
+ extends Utils.ParseFile
+ {
+ public void execute(String file)
+ throws IOException, SAXException
+ {
+ Collection store = new ArrayList();
+ new BaseSaxPerfTest.CopyAndStoreDataSaxHandler(_xercesSaxParser, store);
+ _xercesSaxParser.parse(new InputSource(new FileInputStream(file)));
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org