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

db4o java,db4o Java版性能测试评估publicclassTestdb4oIndex{publicstaticclassRecord{StringstrKey;longintKey;};publicstaticclassAssert{publicstaticvoidthat(booleancondition){if(!condition){thrownewError(“Assertio…

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

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.net/162596.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java的反射机制带来的好处_线程安全与线程不安全

    java的反射机制带来的好处_线程安全与线程不安全什么是反射Java的反射(reflection)机制是指在程序的运行状态中,可以构造任意一个类的对象,可以了解任意一个对象所属的类,可以了解任意一个类的成员变量和方法,可以调用任意一个对象的属性和方法jdbc(数据库连接技术)在加载驱动时运用到了反射技术例如:实例化对象第一种:Personp=newPerson()虚拟机在执行的时候已经确切知道要实例化哪个类的对象第二种:反射:虚拟机在实例化对象的时候,可以事先不知道要实例化哪个类的对象,传参的时候虚拟机根据参数确定要实例化哪个类的

    2022年8月24日
    5
  • RabbitMQ Network Partitions

    RabbitMQ Network PartitionsClusteringandNetworkPartitionsRabbitMQclustersdonottoleratenetworkpartitionswell.IfyouarethinkingofclusteringacrossaWAN,don’t.Youshouldusefederationortheshovelinstead.H

    2022年6月26日
    28
  • c语言list嵌套遍历「建议收藏」

    c语言list嵌套遍历「建议收藏」list::iteratoritor; //定义迭代器 listmyList1; listmyList2;list>bigList;myList1.push_back(“88”);myList1.push_back(“99”);myList2.push_back(“22”);myList2.push_back(“33”);bigLi

    2022年7月12日
    35
  • pycharm使用远程python虚拟环境_pycharm自带python吗

    pycharm使用远程python虚拟环境_pycharm自带python吗虽然pycharm很耗内存,但这依然阻挡不了它灰常好用的优势,电脑配置不够的话建议选择19年的pycharm版本,16G的内存带2021.2.1运行起来是这样:首先确定pycharm用的是专业版,社区版不提供远程服务的功能。1.配置远程服务器信息并测试菜单栏Tools—->Deployment—->Configuration显示如下界面:新建一个连接,协议类型选择SFTP,不要选其他两种,其他两种实现的功能不一样,并且一般服务器上也不会开放21端口,SFTP使用的是

    2022年8月27日
    3
  • ubuntu-14.04 系统安装mysql-5.6.21

    ubuntu-14.04 系统安装mysql-5.6.21

    2022年1月6日
    41
  • Echarts网格颜色渐变 + 折线图折线发光高亮效果

    Echarts网格颜色渐变 + 折线图折线发光高亮效果series:里面定义折线发光高亮的效果网格颜色的渐变附上封住代码

    2025年8月12日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号