前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >db4o java,db4o Java版性能测试评估

db4o java,db4o Java版性能测试评估

作者头像
全栈程序员站长
发布2022-09-13 21:57:03
2110
发布2022-09-13 21:57:03
举报

大家好,又见面了,我是你们的朋友全栈君。

public class Testdb4oIndex {

public static class Record {

String strKey;

long intKey;

};

public static class Assert {

public static void that(boolean condition) {

if (!condition) {

throw new Error(“Assertion failed”);

}

}

}

static final String FILE = “testindex.yap”;

final static int nRecords = 100000;

static public void main(String[] args) {

new File(FILE).delete();

Configuration conf = Db4o.configure();

conf.objectClass(Record.class).objectField(“strKey”).indexed(true);

conf.objectClass(Record.class).objectField(“intKey”).indexed(true);

conf.weakReferences(false);

conf.discardFreeSpace(Integer.MAX_VALUE);

conf.automaticShutDown(false);

conf.lockDatabaseFile(false);

ObjectContainer db = Db4o.openFile(FILE);

long start = System.currentTimeMillis();

long key = 1999;

int i;

for (i = 0; i < nRecords; i++) {

Record rec = new Record();

key = (3141592621L*key + 2718281829L) % 1000000007L;

rec.intKey = key;

rec.strKey = Long.toString(key);

db.set(rec);

}

db.commit();

System.out.println(“Elapsed time for inserting ” + nRecords + ” records: “

+ (System.currentTimeMillis() – start) + ” milliseconds”);

start = System.currentTimeMillis();

key = 1999;

for (i = 0; i < nRecords; i++) {

key = (3141592621L*key + 2718281829L) % 1000000007L;

Query q = db.query();

q.constrain(Record.class);

q.descend(“intKey”).constrain(new Long(key));

Record rec1 = (Record)q.execute().next();

q = db.query();

q.constrain(Record.class);

q.descend(“strKey”).constrain(Long.toString(key));

Record rec2 = (Record)q.execute().next();

Assert.that(rec1 != null && rec1 == rec2);

}

System.out.println(“Elapsed time for performing ” + nRecords*2 + ” index searches: “

+ (System.currentTimeMillis() – start) + ” milliseconds”);

start = System.currentTimeMillis();

Query q = db.query();

q.constrain(Record.class);

ObjectSet objectSet = q.execute();

while(objectSet.hasNext()){

db.delete(objectSet.next());

}

db.commit();

System.out.println(“Elapsed time for deleting ” + nRecords + ” records: “

+ (System.currentTimeMillis() – start) + ” milliseconds”);

db.close();

}

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/162596.html原文链接:https://javaforall.cn

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com