⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcachesize.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            long time = sw.elapsedTime();            long rate = ((long) bigrows * 1000) / (time + 1);            storeResult("count (index on id)", rs.getInt(1), time, rate);            System.out.println("count time (index on id) " + rs.getInt(1)                               + " rows  -- " + time + " ms -- " + rate                               + " tps");        } catch (SQLException e) {}    }    private void countTestZip() {        try {            StopWatch sw = new StopWatch();            sStatement.execute("SELECT count(*) from TEST where zip > -1");            ResultSet rs = sStatement.getResultSet();            rs.next();            long time = (long) sw.elapsedTime();            long rate = ((long) bigrows * 1000) / (time + 1);            storeResult("count (index on zip)", rs.getInt(1), time, rate);            System.out.println("count time (index on zip) " + rs.getInt(1)                               + " rows  -- " + time + " ms -- " + rate                               + " tps");        } catch (SQLException e) {}    }    private void countZip() {        try {            StopWatch sw = new StopWatch();            sStatement.execute("SELECT count(*) from zip where zip > -1");            ResultSet rs = sStatement.getResultSet();            rs.next();            System.out.println("count time (zip table) " + rs.getInt(1)                               + " rows  -- " + sw.elapsedTime() + " ms");        } catch (SQLException e) {}    }    private void updateZip() {        StopWatch        sw        = new StopWatch();        java.util.Random randomgen = new java.util.Random();        int              i         = 0;        boolean          slow      = false;        int              count     = 0;        int              random    = 0;        try {            PreparedStatement ps = cConnection.prepareStatement(                "UPDATE test SET filler = filler || zip WHERE zip = ?");            for (; i < smallrows; i++) {                random = nextIntRandom(randomgen, smallrows - 1);                ps.setInt(1, random);                count += ps.executeUpdate();                if (reportProgress && count % 10000 < 20) {                    System.out.println("Update " + count + " : "                                       + (sw.elapsedTime() + 1));                }            }            ps.close();        } catch (SQLException e) {            System.out.println("error : " + random);            e.printStackTrace();        }        long time = sw.elapsedTime();        long rate = (i * 1000) / (time + 1);        storeResult("update with random zip", i, time, rate);        System.out.println("update time with random zip " + i + " rows  -- "                           + time + " ms -- " + rate + " tps");    }    void updateID() {        StopWatch        sw        = new StopWatch();        java.util.Random randomgen = new java.util.Random();        int              i         = 0;        boolean          slow      = false;        int              count     = 0;        int              random    = 0;        try {            PreparedStatement ps = cConnection.prepareStatement(                "UPDATE test SET zip = zip + 1 WHERE id = ? and zip <> "                + smallrows);            for (i = 0; i < bigops; i++) {                random = nextIntRandom(randomgen, bigrows - 1);                ps.setInt(1, random);                ps.execute();                if (reportProgress && (i + 1) % 10000 == 0                        || (slow && (i + 1) % 100 == 0)) {                    System.out.println("Update " + (i + 1) + " : "                                       + sw.elapsedTime() + " rps: "                                       + (i * 1000 / (sw.elapsedTime() + 1)));                }            }            ps.close();        } catch (SQLException e) {            System.out.println("error : " + random);            e.printStackTrace();        }        long time = sw.elapsedTime();        long rate = (i * 1000) / (time + 1);        storeResult("update with random id", i, time, rate);        System.out.println("update time with random id " + i + " rows  -- "                           + time + " ms -- " + rate + " tps");    }    void updateIDLinear() {        StopWatch        sw        = new StopWatch();        java.util.Random randomgen = new java.util.Random();        int              i         = 0;        boolean          slow      = false;        int              count     = 0;        int              random    = 0;        try {            PreparedStatement ps = cConnection.prepareStatement(                "UPDATE test SET zip = zip + 1 WHERE id = ? and zip <> "                + smallrows);            for (i = 0; i < bigops; i++) {                random = i;                ps.setInt(1, random);                ps.execute();                if (reportProgress && (i + 1) % 10000 == 0                        || (slow && (i + 1) % 100 == 0)) {                    System.out.println("Update " + (i + 1) + " : "                                       + sw.elapsedTime() + " rps: "                                       + (i * 1000 / (sw.elapsedTime() + 1)));                }            }            ps.close();        } catch (SQLException e) {            System.out.println("error : " + random);            e.printStackTrace();        }        long time = sw.elapsedTime();        long rate = (i * 1000) / (time + 1);        storeResult("update with sequential id", i, time, rate);        System.out.println("update time with sequential id " + i                           + " rows  -- " + time + " ms -- " + rate + " tps");    }    void deleteTest() {        StopWatch        sw        = new StopWatch();        java.util.Random randomgen = new java.util.Random();        int              i         = 0;        boolean          slow      = false;        int              count     = 0;        int              random    = 0;        try {            PreparedStatement ps =                cConnection.prepareStatement("DELETE FROM test WHERE id = ?");            for (i = 0; count < smallops; i++) {                random = nextIntRandom(randomgen, bigrows);//                random = i;                ps.setInt(1, random);                count += ps.executeUpdate();                if (reportProgress && (i + 1) % 10000 == 0                        || (slow && (i + 1) % 100 == 0)) {                    System.out.println("delete " + (i + 1) + " : "                                       + sw.elapsedTime() + " rps: "                                       + (i * 1000 / (sw.elapsedTime() + 1)));                }            }            ps.close();        } catch (SQLException e) {            System.out.println("error : " + random);            e.printStackTrace();        }        long time = sw.elapsedTime();        long rate = (count * 1000) / (time + 1);        storeResult("delete with random id", count, time, rate);        System.out.println("delete time for random id " + count                           + " rows  -- " + time + " ms -- " + rate + " tps");    }    void deleteZipTable() {        StopWatch        sw        = new StopWatch();        java.util.Random randomgen = new java.util.Random();        int              i         = 0;        boolean          slow      = false;        int              count     = 0;        int              random    = 0;        try {            PreparedStatement ps =                cConnection.prepareStatement("DELETE FROM zip WHERE zip = ?");            for (i = 0; i <= smallrows; i++) {//                random = randomgen.nextInt(smallrows - 1);                random = i;                ps.setInt(1, random);                count += ps.executeUpdate();                if (reportProgress && (i + 1) % 10000 == 0                        || (slow && (i + 1) % 100 == 0)) {                    System.out.println("delete " + (i + 1) + " : "                                       + sw.elapsedTime() + " rps: "                                       + (i * 1000 / (sw.elapsedTime() + 1)));                }            }            ps.close();        } catch (SQLException e) {            System.out.println("error : " + random);            e.printStackTrace();        }        long time = sw.elapsedTime();        long rate = ((long) count * 1000) / (time + 1);        storeResult("delete with random zip", count, time, rate);        System.out.println("delete time for random zip " + count                           + " rows  -- " + time + " ms -- " + rate + " tps");    }    void storeResult(String description, int count, long time, long rate) {        try {            writer.write("<tr><td>" + description + "</td><td>" + count                         + "</td><td>" + time + "</td><td>" + rate                         + "</td></tr>\n");        } catch (Exception e) {}    }    static void deleteDatabase(String path) {        FileUtil.delete(path + ".backup");        FileUtil.delete(path + ".properties");        FileUtil.delete(path + ".script");        FileUtil.delete(path + ".data");        FileUtil.delete(path + ".log");        FileUtil.delete(path + ".lck");        FileUtil.delete(path + ".csv");    }    int nextIntRandom(Random r, int range) {        int b = Math.abs(r.nextInt());        return b % range;    }    public static void main(String[] argv) {        TestCacheSize  test  = new TestCacheSize();        HsqlProperties props = HsqlProperties.argArrayToProps(argv, "test");        test.bigops   = props.getIntegerProperty("test.bigops", test.bigops);        test.bigrows  = test.bigops;        test.smallops = test.bigops / 8;        test.cacheScale = props.getIntegerProperty("test.scale",                test.cacheScale);        test.logType   = props.getProperty("test.logtype", test.logType);        test.tableType = props.getProperty("test.tabletype", test.tableType);        test.nioMode   = props.isPropertyTrue("test.nio", test.nioMode);        if (props.getProperty("test.dbtype", "").equals("mem")) {            test.filepath = "mem:test";            test.filedb   = false;            test.shutdown = false;        }        test.setUp();        StopWatch sw = new StopWatch();        test.testFillUp();        test.checkResults();        long time = sw.elapsedTime();        test.storeResult("total test time", 0, (int) time, 0);        System.out.println("total test time -- " + sw.elapsedTime() + " ms");        test.tearDown();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -