001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jmeter.monitor.model.benchmark;
018:
019: /**
020: *
021: * @version $Revision: 493796 $ on $Date: 2007-01-07 18:31:05 +0000 (Sun, 07 Jan 2007) $
022: */
023: public class ParseBenchmark {
024:
025: /**
026: *
027: */
028: public ParseBenchmark() {
029: super ();
030: }
031:
032: public static void main(String[] args) {
033: if (args.length == 3) {
034: int parser = 0;
035: String file = null;
036: int loops = 1000;
037: if (args[0] != null) {
038: if (!args[0].equals("jaxb")) {
039: parser = 1;
040: }
041: }
042: if (args[1] != null) {
043: file = args[1];
044: }
045: if (args[2] != null) {
046: loops = Integer.parseInt(args[2]);
047: }
048:
049: java.io.File infile = new java.io.File(file);
050: java.io.FileInputStream fis = null;
051: java.io.InputStreamReader isr = null;
052: StringBuffer buf = new StringBuffer();
053: try {
054: fis = new java.io.FileInputStream(infile);
055: isr = new java.io.InputStreamReader(fis);
056: java.io.BufferedReader br = new java.io.BufferedReader(
057: isr);
058: String line = null;
059: while ((line = br.readLine()) != null) {
060: buf.append(line);
061: }
062: } catch (Exception e) {
063: e.printStackTrace();
064: }
065: long start = 0;
066: long end = 0;
067: String contents = buf.toString().trim();
068: System.out.println("start test: " + loops + " iterations");
069: System.out.println("content:");
070: System.out.println(contents);
071:
072: if (parser == 0) {
073: /**
074: * try { JAXBContext jxbc = new
075: * org.apache.jorphan.tomcat.manager.ObjectFactory();
076: * Unmarshaller mar = jxbc.createUnmarshaller();
077: *
078: * start = System.currentTimeMillis(); for (int idx=0; idx <
079: * loops; idx++){ StreamSource ss = new StreamSource( new
080: * ByteArrayInputStream(contents.getBytes())); Object ld =
081: * mar.unmarshal(ss); } end = System.currentTimeMillis();
082: * System.out.println("elapsed Time: " + (end - start)); } catch
083: * (JAXBException e){ }
084: */
085: } else {
086: org.apache.jmeter.monitor.model.ObjectFactory of = org.apache.jmeter.monitor.model.ObjectFactory
087: .getInstance();
088: start = System.currentTimeMillis();
089: for (int idx = 0; idx < loops; idx++) {
090: // NOTUSED org.apache.jmeter.monitor.model.Status st =
091: of.parseBytes(contents.getBytes());
092: }
093: end = System.currentTimeMillis();
094: System.out.println("elapsed Time: " + (end - start));
095: }
096:
097: } else {
098: System.out.println("missing paramters:");
099: System.out.println("parser file iterations");
100: System.out.println("example: jaxb status.xml 1000");
101: }
102: }
103: }
|