12 |
|
|
13 |
public class TestServlet extends HttpServlet { |
public class TestServlet extends HttpServlet { |
14 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
15 |
final int COUNT = 10; |
|
16 |
|
Random r = new Random(); |
17 |
|
|
18 |
//South-West corner= 54.0, 7.0 |
//South-West corner= 54.5, 8.0 |
19 |
//North-East corner= 58.0, 16.0 |
//North-East corner= 57.8, 12.7 |
20 |
//Latitude span=4.0 |
//Latitude span=3.3 |
21 |
//Longitude span=9.0 |
//Longitude span=4.7 |
22 |
void testFindNearest() throws SQLException { |
void testFindNearest(int count) throws SQLException { |
|
Random r = new Random(); |
|
23 |
|
|
24 |
StationDAO db = new StationDAO(); |
StationDAO db = new StationDAO(); |
25 |
|
|
26 |
|
|
27 |
for (int i=0; i<COUNT; i++) { |
for (int i=0; i<count; i++) { |
28 |
float lat = (r.nextFloat()*4.0F) + 54.0F; |
float lat = (r.nextFloat()*3.3F) + 54.5F; |
29 |
float lng = (r.nextFloat()*9.0F) + 7.0F; |
float lng = (r.nextFloat()*4.7F) + 8.0F; |
30 |
db.getByLocation(lat, lng); |
db.getByLocation(lat, lng); |
31 |
} |
} |
32 |
|
|
34 |
|
|
35 |
} |
} |
36 |
|
|
37 |
void testFindName() throws SQLException { |
void testFindName(int count) throws SQLException { |
|
Random r = new Random(); |
|
38 |
|
|
39 |
StationDAO db = new StationDAO(); |
StationDAO db = new StationDAO(); |
40 |
|
|
41 |
for (int i=0; i<COUNT; i++) { |
for (int i=0; i<count; i++) { |
42 |
char c1 = ((char)r.nextInt(26)); |
char c1 = ((char)r.nextInt(26)); |
43 |
c1 += 'a'; |
c1 += 'a'; |
44 |
char c2 = ((char)r.nextInt(26)) ; |
char c2 = ((char)r.nextInt(26)) ; |
49 |
|
|
50 |
db.getByName(search); |
db.getByName(search); |
51 |
} |
} |
52 |
|
} |
53 |
|
|
54 |
|
void testFindFavorites(int count) throws SQLException { |
55 |
|
|
56 |
|
StationDAO db = new StationDAO(); |
57 |
|
|
58 |
|
for (int i=0; i<count; i++) { |
59 |
|
final int MAX = 8; |
60 |
|
|
61 |
|
StringBuilder sb = new StringBuilder(); |
62 |
|
sb.append('('); |
63 |
|
for (int j=0; j<MAX;j++) { |
64 |
|
if (j>0) |
65 |
|
sb.append(','); |
66 |
|
sb.append(r.nextInt(400)); |
67 |
|
} |
68 |
|
sb.append(')'); |
69 |
|
|
70 |
|
|
71 |
|
db.getByList(sb.toString()); |
72 |
|
} |
73 |
} |
} |
74 |
|
|
75 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
76 |
|
|
77 |
|
if (true) { |
78 |
|
|
79 |
|
return; |
80 |
|
} |
81 |
|
|
82 |
|
String test = request.getParameter("test"); |
83 |
|
String strCount = request.getParameter("count"); |
84 |
|
int count = Integer.parseInt(strCount); |
85 |
|
|
86 |
|
|
87 |
try { |
try { |
88 |
long start = System.currentTimeMillis(); |
long start = System.currentTimeMillis(); |
89 |
testFindName(); |
|
90 |
|
if ( test.equals("name") ) { |
91 |
|
testFindName(count); |
92 |
|
} else if ( test.equals("nearest") ) { |
93 |
|
testFindNearest(count); |
94 |
|
} else if ( test.equals("favorites") ) { |
95 |
|
testFindFavorites(count); |
96 |
|
} else { |
97 |
|
throw new ServletException("No parameter test"); |
98 |
|
} |
99 |
|
|
100 |
long stop = System.currentTimeMillis(); |
long stop = System.currentTimeMillis(); |
101 |
|
|
102 |
long elapsed = stop-start; |
long elapsed = stop-start; |
103 |
|
|
104 |
float avg = ((float)elapsed) / COUNT; |
float avg = ((float)elapsed) / count; |
105 |
|
|
106 |
String out = "Count=" + COUNT + "\n" + |
String out = "Count=" + count + "\n" + |
107 |
"Elapsed=" + elapsed + "\n" + |
"Elapsed=" + elapsed + "\n" + |
108 |
"Avg.=" + avg; |
"Avg.=" + avg; |
109 |
|
|