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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 735 by torben, Tue May 18 20:58:04 2010 UTC revision 736 by torben, Tue May 18 21:07:02 2010 UTC
# Line 12  import javax.servlet.http.HttpServletRes Line 12  import javax.servlet.http.HttpServletRes
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;
         final int COUNT = 10;  
15    
16          //South-West corner= 54.0, 7.0          //South-West corner= 54.0, 7.0
17          //North-East corner= 58.0, 16.0          //North-East corner= 58.0, 16.0
18          //Latitude span=4.0          //Latitude span=4.0
19          //Longitude span=9.0          //Longitude span=9.0
20          void testFindNearest() throws SQLException {          void testFindNearest(int count) throws SQLException {
21                  Random r = new Random();                  Random r = new Random();
22    
23                  StationDAO db = new StationDAO();                  StationDAO db = new StationDAO();
24    
25    
26                  for (int i=0; i<COUNT; i++) {                  for (int i=0; i<count; i++) {
27                          float lat = (r.nextFloat()*4.0F) + 54.0F;                          float lat = (r.nextFloat()*4.0F) + 54.0F;
28                          float lng = (r.nextFloat()*9.0F) + 7.0F;                          float lng = (r.nextFloat()*9.0F) + 7.0F;
29                          db.getByLocation(lat, lng);                          db.getByLocation(lat, lng);
# Line 34  public class TestServlet extends HttpSer Line 33  public class TestServlet extends HttpSer
33    
34          }          }
35    
36          void testFindName()  throws SQLException {          void testFindName(int count)  throws SQLException {
37                  Random r = new Random();                  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)) ;
# Line 56  public class TestServlet extends HttpSer Line 55  public class TestServlet extends HttpSer
55          }          }
56    
57          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
58                    
59                    
60                    String test = request.getParameter("test");
61                    String strCount = request.getParameter("count");
62                    int count = Integer.parseInt(strCount);
63                    
64            
65                  try {                                    try {                  
66                          long start = System.currentTimeMillis();                          long start = System.currentTimeMillis();
67                          testFindName();                          
68                            if ( test.equals("name") ) {
69                                    testFindName(count);
70                            } else if ( test.equals("nearest") ) {
71                                    testFindNearest(count);
72                            } else {
73                                    throw new ServletException("No parameter test");
74                            }
75                            
76                          long stop = System.currentTimeMillis();                          long stop = System.currentTimeMillis();
77    
78                          long elapsed = stop-start;                          long elapsed = stop-start;
79    
80                          float avg = ((float)elapsed) / COUNT;                          float avg = ((float)elapsed) / count;
81    
82                          String out = "Count=" + COUNT + "\n" +                                                            String out = "Count=" + count + "\n" +                                  
83                          "Elapsed=" + elapsed + "\n" +                          "Elapsed=" + elapsed + "\n" +
84                          "Avg.=" +  avg;                          "Avg.=" +  avg;
85    

Legend:
Removed from v.735  
changed lines
  Added in v.736

  ViewVC Help
Powered by ViewVC 1.1.20