1 5 package org.h2.test.db; 6 7 import java.sql.Connection ; 8 import java.sql.PreparedStatement ; 9 import java.sql.Statement ; 10 11 import org.h2.test.TestBase; 12 13 16 17 public class TestSpeed extends TestBase { 18 19 23 25 public void test() throws Exception { 26 27 deleteDb("speed"); 28 Connection conn; 29 30 conn = getConnection("speed"); 31 32 34 37 Statement stat = conn.createStatement(); 38 stat.execute("DROP TABLE IF EXISTS TEST"); 39 stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"); 40 int len = getSize(1, 10000); 41 for(int i=0; i<len; i++) { 42 stat.execute("SELECT ID, NAME FROM TEST ORDER BY ID"); 43 } 44 45 50 51 long time = System.currentTimeMillis(); 58 72 78 90 92 stat.execute("DROP TABLE IF EXISTS TEST"); 93 stat.execute("CREATE CACHED TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"); 94 PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?)"); 95 96 int max = getSize(1, 10000); 97 for(int i=0; i<max; i++) { 98 prep.setInt(1, i); 99 prep.setString(2, "Helloasdfaldsjflajdflajdslfoajlskdfkjasdfadsfasdfadsfadfsalksdjflasjflajsdlkfjaksdjflkskd" + i); 100 prep.execute(); 102 } 112 113 116 time = System.currentTimeMillis() - time; 117 trace(time+" insert"); 118 119 121 127 129 time = System.currentTimeMillis(); 130 131 prep = conn.prepareStatement("UPDATE TEST SET NAME='Another data row which is long' WHERE ID=?"); 132 for(int i=0; i<max; i++) { 133 prep.setInt(1, i); 134 prep.execute(); 135 136 } 146 154 time = System.currentTimeMillis() - time; 155 trace(time+" update"); 156 157 conn.close(); 158 time = System.currentTimeMillis() - time; 159 trace(time+" close"); 160 } 161 162 166 170 174 182 184 201 210 211 213 220 227 233 236 239 241 242 243 244 246 251 253 254 255 269 271 274 278 280 286 292 293 294 296 308 310 315 327 329 342 344 355 362 368 375 381 389 391 404 } 405 | Popular Tags |