2
Copyright (C) 2002-2004 MySQL AB
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of version 2 of the GNU General Public License as
6
published by the Free Software Foundation.
8
There are special exceptions to the terms and conditions of the GPL
9
as it is applied to this software. View the full text of the
10
exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11
software distribution.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
package testsuite.perf;
27
import testsuite.BaseTestCase;
30
* Simplistic test for performance regression.
32
* @author Mark Matthews
34
public class RetrievalPerfTest extends BaseTestCase {
35
// ~ Static fields/initializers
36
// ---------------------------------------------
38
private static final int NUM_TESTS = 10000;
40
private static final int NUM_ROWS = 80;
43
// -----------------------------------------------------------
46
* Constructor for RetrievalPerfTest.
49
* name of the test to run
51
public RetrievalPerfTest(String name) {
56
// ----------------------------------------------------------------
64
public static void main(String[] args) {
65
new RetrievalPerfTest("testRetrievalMyIsam").run();
66
new RetrievalPerfTest("testRetrievalHeap").run();
67
new RetrievalPerfTest("testRetrievalCached").run();
71
* @see junit.framework.TestCase#setUp()
73
public void setUp() throws Exception {
75
this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestHeap");
76
this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestMyIsam");
78
.executeUpdate("CREATE TABLE retrievalPerfTestHeap (priKey INT NOT NULL PRIMARY KEY,"
79
+ "charField VARCHAR(80)) TYPE=HEAP");
81
.executeUpdate("CREATE TABLE retrievalPerfTestMyIsam (priKey INT NOT NULL PRIMARY KEY,"
82
+ "charField VARCHAR(80)) TYPE=MyISAM");
84
for (int i = 0; i < NUM_ROWS; i++) {
86
.executeUpdate("INSERT INTO retrievalPerfTestHeap (priKey, charField) VALUES ("
88
+ ",'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')");
90
.executeUpdate("INSERT INTO retrievalPerfTestMyIsam (priKey, charField) VALUES ("
92
+ ",'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')");
97
* @see junit.framework.TestCase#tearDown()
99
public void tearDown() throws Exception {
100
this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestHeap");
101
this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestMyIsam");
106
* Tests retrieval from the query cache
111
public void testRetrievalCached() throws Exception {
112
this.stmt.executeUpdate("SET QUERY_CACHE_TYPE = DEMAND");
114
double fullBegin = System.currentTimeMillis();
115
double averageQueryTimeMs = 0;
116
double averageTraversalTimeMs = 0;
118
for (int i = 0; i < NUM_TESTS; i++) {
119
long queryBegin = System.currentTimeMillis();
121
.executeQuery("SELECT SQL_CACHE * FROM retrievalPerfTestHeap");
123
long queryEnd = System.currentTimeMillis();
124
averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);
126
long traverseBegin = System.currentTimeMillis();
128
while (this.rs.next()) {
130
this.rs.getString(2);
133
long traverseEnd = System.currentTimeMillis();
134
averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
137
double fullEnd = System.currentTimeMillis();
138
double fullTime = (fullEnd - fullBegin) / 1000;
139
double queriesPerSec = NUM_TESTS / fullTime;
140
double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
141
System.out.println("\nQuery Cache From Heap Retrieval\n");
142
System.out.println("Full test took: " + fullTime + " seconds.");
143
System.out.println("Queries/second: " + queriesPerSec);
144
System.out.println("Rows/second: " + rowsPerSec);
145
System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs
147
System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs
150
// We're doing something wrong if we can't beat 45 seconds :(
151
assertTrue(fullTime < 45);
155
* Tests retrieval from HEAP tables
160
public void testRetrievalHeap() throws Exception {
161
double fullBegin = System.currentTimeMillis();
162
double averageQueryTimeMs = 0;
163
double averageTraversalTimeMs = 0;
165
for (int i = 0; i < NUM_TESTS; i++) {
166
long queryBegin = System.currentTimeMillis();
168
.executeQuery("SELECT * FROM retrievalPerfTestHeap");
170
long queryEnd = System.currentTimeMillis();
171
averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);
173
long traverseBegin = System.currentTimeMillis();
175
while (this.rs.next()) {
177
this.rs.getString(2);
180
long traverseEnd = System.currentTimeMillis();
181
averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
184
double fullEnd = System.currentTimeMillis();
185
double fullTime = (fullEnd - fullBegin) / 1000;
186
double queriesPerSec = NUM_TESTS / fullTime;
187
double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
188
System.out.println("\nHEAP Table Retrieval\n");
189
System.out.println("Full test took: " + fullTime + " seconds.");
190
System.out.println("Queries/second: " + queriesPerSec);
191
System.out.println("Rows/second: " + rowsPerSec);
192
System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs
194
System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs
197
// We're doing something wrong if we can't beat 45 seconds :(
198
assertTrue(fullTime < 45);
202
* Tests retrieval speed from MyISAM type tables
207
public void testRetrievalMyIsam() throws Exception {
208
double fullBegin = System.currentTimeMillis();
209
double averageQueryTimeMs = 0;
210
double averageTraversalTimeMs = 0;
212
for (int i = 0; i < NUM_TESTS; i++) {
213
long queryBegin = System.currentTimeMillis();
215
.executeQuery("SELECT * FROM retrievalPerfTestMyIsam");
217
long queryEnd = System.currentTimeMillis();
218
averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);
220
long traverseBegin = System.currentTimeMillis();
222
while (this.rs.next()) {
224
this.rs.getString(2);
227
long traverseEnd = System.currentTimeMillis();
228
averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
231
double fullEnd = System.currentTimeMillis();
232
double fullTime = (fullEnd - fullBegin) / 1000;
233
double queriesPerSec = NUM_TESTS / fullTime;
234
double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
235
System.out.println("\nMyIsam Retrieval\n");
236
System.out.println("Full test took: " + fullTime + " seconds.");
237
System.out.println("Queries/second: " + queriesPerSec);
238
System.out.println("Rows/second: " + rowsPerSec);
239
System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs
241
System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs
244
// We're doing something wrong if we can't beat 45 seconds :(
245
assertTrue(fullTime < 45);