KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > monitor > model > benchmark > ParseBenchmark


1 // $Header: /home/cvs/jakarta-jmeter/src/monitor/model/org/apache/jmeter/monitor/model/benchmark/ParseBenchmark.java,v 1.4.2.1 2004/10/11 00:58:39 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.jmeter.monitor.model.benchmark;
18
19 /**
20  *
21  * @version $Revision: 1.4.2.1 $ on $Date: 2004/10/11 00:58:39 $
22  */

23 public class ParseBenchmark
24 {
25
26     /**
27      *
28      */

29     public ParseBenchmark()
30     {
31         super();
32     }
33
34     public static void main(String JavaDoc[] args)
35     {
36         if (args.length == 3){
37             int parser = 0;
38             String JavaDoc file = null;
39             int loops = 1000;
40             if (args[0] != null){
41                 if (!args[0].equals("jaxb")){
42                     parser = 1;
43                 }
44             }
45             if (args[1] != null){
46                 file = args[1];
47             }
48             if (args[2] != null){
49                 loops = Integer.parseInt(args[2]);
50             }
51
52             java.io.File JavaDoc infile = new java.io.File JavaDoc(file);
53             java.io.FileInputStream JavaDoc fis = null;
54             java.io.InputStreamReader JavaDoc isr = null;
55             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
56             try {
57                 fis = new java.io.FileInputStream JavaDoc(infile);
58                 isr = new java.io.InputStreamReader JavaDoc(fis);
59                 java.io.BufferedReader JavaDoc br = new java.io.BufferedReader JavaDoc(isr);
60                 String JavaDoc line = null;
61                 while ((line = br.readLine()) != null){
62                     buf.append(line);
63                 }
64             } catch (Exception JavaDoc e){
65                 e.printStackTrace();
66             }
67             long start = 0;
68             long end = 0;
69             String JavaDoc contents = buf.toString().trim();
70             System.out.println("start test: " + loops + " iterations");
71             System.out.println("content:");
72             System.out.println(contents);
73             
74             if (parser == 0){
75                 /**
76                 try {
77                     JAXBContext jxbc =
78                         new org.apache.jorphan.tomcat.manager.ObjectFactory();
79                     Unmarshaller mar = jxbc.createUnmarshaller();
80                         
81                     start = System.currentTimeMillis();
82                     for (int idx=0; idx < loops; idx++){
83                         StreamSource ss = new StreamSource(
84                             new ByteArrayInputStream(contents.getBytes()));
85                         Object ld = mar.unmarshal(ss);
86                     }
87                     end = System.currentTimeMillis();
88                     System.out.println("elapsed Time: " + (end - start));
89                 } catch (JAXBException e){
90                 }
91                 **/

92             } else {
93                 org.apache.jmeter.monitor.model.ObjectFactory of =
94                     org.apache.jmeter.monitor.model.ObjectFactory.getInstance();
95                 start = System.currentTimeMillis();
96                 for (int idx=0; idx < loops; idx++){
97                     //NOTUSED org.apache.jmeter.monitor.model.Status st =
98
of.parseBytes(contents.getBytes());
99                 }
100                 end = System.currentTimeMillis();
101                 System.out.println("elapsed Time: " + (end - start));
102             }
103             
104         } else {
105             System.out.println("missing paramters:");
106             System.out.println("parser file iterations");
107             System.out.println("example: jaxb status.xml 1000");
108         }
109     }
110 }
111
Popular Tags