KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > Performance


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ----------------
23  * Performance.java
24  * ----------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited).
28  * Contributor(s): -;
29  *
30  * $Id: Performance.java,v 1.5 2003/06/13 15:46:06 mungady Exp $
31  *
32  * Changes (since 11-Oct-2002)
33  * ---------------------------
34  * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
35  *
36  */

37 package org.jfree.chart.demo;
38
39 import java.awt.geom.Line2D JavaDoc;
40 import java.util.Date JavaDoc;
41
42 /**
43  * A basic performance test for a couple of common operations.
44  *
45  * @author David Gilbert
46  */

47 public class Performance {
48
49     /** The value. */
50     private double value = 2.0;
51
52     /** The number. */
53     private Double JavaDoc number = new Double JavaDoc(value);
54
55     /**
56      * Default constructor.
57      */

58     public Performance() {
59     }
60
61     /**
62      * Creates lines in a loop.
63      *
64      * @param count the number of lines to create.
65      */

66     public void createLines(int count) {
67
68         Line2D JavaDoc line = new Line2D.Double JavaDoc();
69         for (int i = 0; i < count; i++) {
70             line = new Line2D.Double JavaDoc(1.0, 1.0, 1.0, 1.0);
71         }
72         System.out.println(line.toString());
73
74     }
75
76     /**
77      * Creates one line, then repeatedly calls the setLine method.
78      *
79      * @param count the number of times to call the setLine method.
80      */

81     public void setLines(int count) {
82
83         Line2D JavaDoc line = new Line2D.Double JavaDoc(0.0, 0.0, 0.0, 0.0);
84         for (int i = 0; i < count; i++) {
85             line.setLine(1.0, 1.0, 1.0, 1.0);
86         }
87
88     }
89
90     /**
91      * Repeatedly grabs a value from a Number instance.
92      *
93      * @param count the number of times to call doubleValue().
94      */

95     public void getNumber(int count) {
96
97         double d = 0.0;
98         for (int i = 0; i < count; i++) {
99             d = this.number.doubleValue();
100         }
101         System.out.println(d);
102
103     }
104
105     /**
106      * Repeatedly grabs a value from a double.
107      *
108      * @param count the number of times to fetch the value.
109      */

110     public void getValue(int count) {
111
112         double d = 0.0;
113         for (int i = 0; i < count; i++) {
114             d = this.value;
115         }
116         System.out.println(d);
117
118     }
119
120     /**
121      * Writes the current time to the console.
122      *
123      * @param text the prefix.
124      * @param time the time.
125      */

126     public void writeTime(String JavaDoc text, Date JavaDoc time) {
127
128         System.out.println(text + " : " + time.getTime());
129
130     }
131
132     /**
133      * Starting point for the application.
134      *
135      * @param args ignored.
136      */

137     public static void main(String JavaDoc[] args) {
138
139         Performance p = new Performance();
140         System.out.println("Simple performance tests.");
141
142         Date JavaDoc start1 = new Date JavaDoc();
143         p.createLines(100000);
144         Date JavaDoc end1 = new Date JavaDoc();
145
146         Date JavaDoc start2 = new Date JavaDoc();
147         p.setLines(100000);
148         Date JavaDoc end2 = new Date JavaDoc();
149
150         p.writeTime("Start create lines", start1);
151         p.writeTime("Finish create lines", end1);
152         p.writeTime("Start set lines", start2);
153         p.writeTime("Finish set lines", end2);
154
155         Date JavaDoc start3 = new Date JavaDoc();
156         p.getNumber(1000000);
157         Date JavaDoc end3 = new Date JavaDoc();
158
159         Date JavaDoc start4 = new Date JavaDoc();
160         p.getValue(1000000);
161         Date JavaDoc end4 = new Date JavaDoc();
162
163         p.writeTime("Start get number", start3);
164         p.writeTime("Finish get number", end3);
165         p.writeTime("Start get value", start4);
166         p.writeTime("Finish get value", end4);
167
168
169     }
170
171 }
172
Popular Tags