Source code: com/eireneh/bible/control/test/Speed.java
1
2 package com.eireneh.bible.control.test;
3
4 import org.w3c.dom.*;
5 import org.apache.xerces.dom.DocumentImpl;
6
7 import com.eireneh.util.*;
8 import com.eireneh.bible.book.*;
9 import com.eireneh.bible.passage.*;
10 import com.eireneh.bible.control.search.*;
11
12 /**
13 * Speed is a simple benchmark that tests how fast a version is. The
14 * current set of tasks that we perform are rather arbitry (sp?).
15 * But that is something that we can improve on when we have more
16 * usage information.
17 *
18 * <p>Progress report. All builds are Debug unless *ed:
19 * <pre>
20 * Date Bible VM Time/s
21 * 1999.12.08 Raw (Mem) HS 1.0.1 20
22 * 1999.12.08 Raw (Mem) MVM 5.00.3167 541
23 * 1999.12.09 Raw (Disk) HS 1.0.1 >600
24 * 1999.12.10 Ser HS 1.0.1 78
25 * 1999.12.11 Ser HS 1.0.1 6.7
26 * 1999.12.11 Raw (Mem) HS 1.0.1 11
27 * 1999.12.11 Raw (Disk) HS 1.0.1 1072
28 * 1999.12.11 Ser MVM 5.00.3167 8
29 * 1999.12.12 Ser HS 1.0.1 4
30 * 1999.12.12 Ser * HS 1.0.1 3
31 * </pre>
32 * </p>
33 *
34 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
35 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
36 * Distribution Licence:<br />
37 * Project B is free software; you can redistribute it
38 * and/or modify it under the terms of the GNU General Public License,
39 * version 2 as published by the Free Software Foundation.<br />
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43 * General Public License for more details.<br />
44 * The License is available on the internet
45 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
46 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
47 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
48 * The copyright to this program is held by it's authors.
49 * </font></td></tr></table>
50 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
51 * @see docs.Licence
52 * @author Joe Walker
53 * @version D0.I0.T0
54 */
55 public class Speed implements Runnable
56 {
57 /**
58 * Basic constructor
59 */
60 public Speed(Bible version)
61 {
62 this.version = version;
63
64 engine = new Engine(version);
65 match = new Matcher(version);
66 }
67
68 /**
69 * This is what to call to execute a benchmark
70 */
71 public void run()
72 {
73 try
74 {
75 start_time = System.currentTimeMillis();
76
77 PassageTally tally;
78
79 // Part 1, a best match, and doc generate
80 tally = match.bestMatch("In the beginning god created the heavens and the earth");
81 tally.trimVerses(35);
82 dummyDisplay(tally);
83 tally = null;
84
85 // Part 2, another best match, and doc generate
86 tally = match.bestMatch("for god so loves the world that he gave his only begotten son");
87 tally.trimVerses(35);
88 dummyDisplay(tally);
89 tally = null;
90
91 // Part 3, a power match, and doc generate
92 String next_input = engine.search("aaron & manna").getName();
93 Passage ref = PassageFactory.createPassage(next_input);
94 ref.trimVerses(35);
95 dummyDisplay(ref);
96 ref = null;
97
98 end_time = System.currentTimeMillis();
99 }
100 catch (Exception ex)
101 {
102 Reporter.informUser(this, ex);
103 }
104 }
105
106 /**
107 * Dummy display routine. We might want to add some XSL styling to this.
108 * @param ref The passage to format for display
109 */
110 private void dummyDisplay(Passage ref) throws Exception
111 {
112 if (ref == null)
113 throw new NullPointerException("Null Passage in dummyDisplay.");
114
115 Document doc = new DocumentImpl();
116 Element ignore = doc.createElement("ignore");
117 doc.appendChild(ignore);
118
119 BibleEle bdoc = new BibleEle(ignore);
120
121 version.getDocument(bdoc, ref);
122 }
123
124 /**
125 * Accessor for the version that we are testing
126 */
127 public long getBenchmark()
128 {
129 if (start_time == 0 || end_time == 0)
130 throw new IllegalStateException("The benchmark has not finished yet.");
131
132 return end_time - start_time;
133 }
134
135 /**
136 * Accessor for the version that we are testing
137 */
138 public Bible getBible()
139 {
140 return version;
141 }
142
143 /**
144 * Accessor for the version that we are testing
145 */
146 public void setBible(Bible version)
147 {
148 this.version = version;
149 }
150
151 /** The search engine. Only used by run() but construction is not under test */
152 private Engine engine = null;
153
154 /** The matching engine. Only used by run() but construction is not under test */
155 private Matcher match = null;
156
157 /** The start time of the benchmark */
158 private long start_time = 0;
159
160 /** The end time of the benchmark */
161 private long end_time = 0;
162
163 /** The version to test */
164 private Bible version;
165 }