XXXXX
C/C++
XXXXX
C#/.net
XXXXX
js
java
java
开发导航 开发导航 www.endv.cn
天云

Verticle SQLConnection 查询时间测试JsonArray比 JsonObject 快5倍

 

  1     public static void main( String[] args ) {
  2         JsonArray line=new JsonArray("[2," +
  3                 "\"test2\"," +
  4                 "2.0," +
  5                 "\"2021-01-19\"," +
  6                 "\"2021-01-19T14:45:16Z\"," +//4
  7                 "\"0\"," +//5
  8                 "false," +
  9                 "0," +//7
 10                 "0.0," +
 11                 "false," +
 12                 "\"0\",\"0\",null]");
 13 
 14         EstList estList=new EstList();
 15         estList.setId(line.getLong(0) ) ; //  id
 16         estList.setName(line.getString(1) ) ; //  name
 17         estList.setDou( line.getDouble(2)) ; //  dou
 18         estList.setDat(new Date(DateUtils.getTimestamp(line.getString(3)).getTime()) ) ; //  dat
 19         Timestamp timestamps=DateUtils.getTimestamp(line.getString(4));
 20         estList.setTimestamps(timestamps) ; //  timestamps
 21         estList.setTex( line.getString(5)) ; //  tex
 22         estList.setTin(line.getBoolean(6) ) ; //  tin
 23         estList.setDeci(line.getDouble(7) ) ; //  dec
 24         estList.setFlo(line.getFloat(8) ) ; //  flo
 25         estList.setBoo(line.getBoolean(9) ) ; //  boo
 26         estList.setLt( line.getString(10)) ; //  lt
 27         estList.setJso( line.getString(11)) ; //  jso
 28         estList.setSmal( line.getString(12)) ; //  smal
 29 //        System.out.println("A对:"+Jsons.toJson(estList));
 30 //        System.out.println("test8882对这排做点什么getString0:"+ja.getLong(0));//2
 31 //        System.out.println("test8882对这排做点什么getString1:"+ja.getString(1));//test2
 32 //        System.out.println("test8882对这排做点什么getString21:"+ja.getDouble(2));//2.0
 33 ////        System.out.println("test8882对这排做点什么getString22:"+ja.getString(2));
 34 //        System.out.println("test8882对这排做点什么getString3:"+ja.getString(3));
 35 //        System.out.println("test8882对这排做点什么getString4:"+ja.getString(4));
 36 //        System.out.println("test8882对这排做点什么getString5:"+ja.getString(5));
 37 //        System.out.println("test8882对这排做点什么getString6:"+ja.getBoolean(6));
 38 //        System.out.println("test8882对这排做点什么getString7:"+ja.getInteger(7));
 39 //        System.out.println("test8882对这排做点什么getString8:"+ja.getDouble(8));
 40 //        System.out.println("test8882对这排做点什么getString9:"+ja.getBoolean(9));
 41 //        System.out.println("test8882对这排做点什么getString10:"+ja.getString(10));
 42 //        System.out.println("test8882对这排做点什么getString11:"+ja.getString(11));
 43 //        System.out.println("test8882对这排做点什么getString12:"+ja.getString(12));
 44 //        System.out.println("test8882对这排做点什么getString12:"+ja.getInteger(12));
 45 //        System.out.println("test8882对这排做点什么getString12:"+ja.getBoolean(12));
 46 //        System.out.println("test8882对这排做点什么getString12:"+ja.getBinary(12));
 47 //        System.out.println("test8882对这排做点什么getString8:"+ja.getBinary(8));
 48     }
 49 
 50 
 51     void query(SQLConnection conn) {
 52         Timestamp closeDate0 =  new Timestamp(System.currentTimeMillis());
 53         query(conn, "SELECT * FROM `test_list` ORDER BY `test_list`.`id` DESC", rs -> {
 54 
 55             Timestamp closeDate1 =  new Timestamp(System.currentTimeMillis());
 56             System.out.println("O0000 设备连接时长:" + (closeDate1.getTime() - closeDate0.getTime())  + "毫秒");//43毫秒
 57             for (JsonObject line : rs.getRows()) {
 58 //                System.out.println(line.encode());
 59 //                Jsons.fromJson(line.encode(),EstList.class);
 60                 EstList tl=Jsons.fromJson(line.encode(),EstList.class);
 61 //                System.out.println(Jsons.toJson(tl));
 62 //                System.out.println("B对:"+Jsons.toJson(tl));
 63             }
 64             Timestamp closeDate2 =  new Timestamp(System.currentTimeMillis());
 65             System.out.println("O0000 设备连接时长:" + (closeDate2.getTime() - closeDate1.getTime())  + "毫秒");//115毫秒
 66             for (JsonArray line : rs.getResults()) {
 67 //                System.out.println(line.encode());
 68                 EstList tl= fromJsonArray(line);
 69 //                System.out.println("A对:"+Jsons.toJson(tl));
 70 //                System.out.println("test8882对这排做点什么getString0:"+line.getList());//2
 71             }
 72             Timestamp closeDate3 =  new Timestamp(System.currentTimeMillis());
 73             System.out.println("O0000 设备连接时长:" + (closeDate3.getTime() - closeDate2.getTime())  + "毫秒");//20毫秒
 74 
 75             // and close the connection
 76             conn.close(done -> {
 77                 if (done.failed()) {
 78                     throw new RuntimeException(done.cause());
 79                 }
 80             });
 81         });
 82     }
 83 
 84     private EstList fromJsonArray(JsonArray line) {
 85         EstList estList=new EstList();
 86 
 87         estList.setId(line.getLong(0) ) ; //  id
 88         estList.setName(line.getString(1) ) ; //  name
 89         estList.setDou( line.getDouble(2)) ; //  dou
 90         estList.setDat(new Date(DateUtils.getTimestamp(line.getString(3)).getTime()) ) ; //  dat
 91         Timestamp timestamps=DateUtils.getTimestamp(line.getString(4));
 92         estList.setTimestamps(timestamps) ; //  timestamps
 93         estList.setTex( line.getString(5)) ; //  tex
 94         estList.setTin(line.getBoolean(6) ) ; //  tin
 95         estList.setDeci(line.getDouble(7) ) ; //  dec
 96         estList.setFlo(line.getFloat(8) ) ; //  flo
 97         estList.setBoo(line.getBoolean(9) ) ; //  boo
 98         estList.setLt( line.getString(10)) ; //  lt
 99         estList.setJso( line.getString(11)) ; //  jso
100         estList.setSmal( line.getString(12)) ; //  smal
101 //        System.out.println("转换:"+Jsons.toJson(estList));
102 
103 //        System.out.println("test8882对这排做点什么getString9:"+ja.getBoolean(9));
104 //        System.out.println("test8882对这排做点什么getString10:"+ja.getString(10));
105 //        System.out.println("test8882对这排做点什么getString11:"+ja.getString(11));
106 //        System.out.println("test8882对这排做点什么getString12:"+ja.getString(12));
107 //        System.out.println("test8882对这排做点什么getString12:"+ja.getInteger(12));
108 //        System.out.println("test8882对这排做点什么getString12:"+ja.getBoolean(12));
109 //        System.out.println("test8882对这排做点什么getString12:"+ja.getBinary(12));
110 //        System.out.println("test8882对这排做点什么getString8:"+ja.getBinary(8));
111 
112         return estList;
113     }

 

150

dao时间:34毫秒 
dao时间:7毫秒  
dao时间:4毫秒  
Verticle JsonArray时间:72毫秒
Verticle JsonArray时间:75毫秒
Verticle JsonArray时间:78毫秒

 

posted @ 2021-01-23 17:33  Endv  阅读(196)  评论(0编辑  收藏  举报