/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/TestServlet.java
ViewVC logotype

Annotation of /android/TrainInfoService/src/dk/thoerup/traininfoservice/TestServlet.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 735 - (hide annotations) (download)
Tue May 18 20:58:04 2010 UTC (14 years ago) by torben
File size: 1672 byte(s)
Some code to test efficiency of the DB queries
1 torben 735 package dk.thoerup.traininfoservice;
2    
3     import java.io.IOException;
4     import java.sql.SQLException;
5     import java.util.Random;
6    
7     import javax.servlet.ServletException;
8     import javax.servlet.http.HttpServlet;
9     import javax.servlet.http.HttpServletRequest;
10     import javax.servlet.http.HttpServletResponse;
11    
12    
13     public class TestServlet extends HttpServlet {
14     private static final long serialVersionUID = 1L;
15     final int COUNT = 10;
16    
17     //South-West corner= 54.0, 7.0
18     //North-East corner= 58.0, 16.0
19     //Latitude span=4.0
20     //Longitude span=9.0
21     void testFindNearest() throws SQLException {
22     Random r = new Random();
23    
24     StationDAO db = new StationDAO();
25    
26    
27     for (int i=0; i<COUNT; i++) {
28     float lat = (r.nextFloat()*4.0F) + 54.0F;
29     float lng = (r.nextFloat()*9.0F) + 7.0F;
30     db.getByLocation(lat, lng);
31     }
32    
33    
34    
35     }
36    
37     void testFindName() throws SQLException {
38     Random r = new Random();
39    
40     StationDAO db = new StationDAO();
41    
42     for (int i=0; i<COUNT; i++) {
43     char c1 = ((char)r.nextInt(26));
44     c1 += 'a';
45     char c2 = ((char)r.nextInt(26)) ;
46     c2 += 'a';
47    
48     String search = "" + c1 + c2;
49     System.out.println(search);
50    
51     db.getByName(search);
52     }
53    
54    
55    
56     }
57    
58     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
59     try {
60     long start = System.currentTimeMillis();
61     testFindName();
62     long stop = System.currentTimeMillis();
63    
64     long elapsed = stop-start;
65    
66     float avg = ((float)elapsed) / COUNT;
67    
68     String out = "Count=" + COUNT + "\n" +
69     "Elapsed=" + elapsed + "\n" +
70     "Avg.=" + avg;
71    
72     response.getWriter().print( out );
73    
74    
75     } catch (Exception e) {
76     throw new ServletException(e);
77     }
78     }
79    
80     }

  ViewVC Help
Powered by ViewVC 1.1.20