<< db4o Java版性能测试评估 | 首页 | 金融危机下软件企业的机遇 >>

Perst Java版性能测试评估

Perst性能测试评估,最近想选择一个轻量、可伸缩、高性能的嵌入式数据库,所以对Perst Java版数据库进行了测试评估。从结果看来Perst Java版还是值得试一试,Perst的性能是db4o,Perst,Jisp,Berkeley DB,JDBM中最出众的

版本:

perst15-271.jar

结果:

Elapsed time for inserting 100000 records: 3359 milliseconds
Elapsed time for performing 200000 index searches: 1578 milliseconds
Elapsed time for deleting 100000 records: 2094 milliseconds

代码:

import org.garret.perst.*;

import java.util.*;

class Record extends Persistent {
    String strKey;
    long   intKey;
};

class Indices extends Persistent {
    Index strIndex;
    Index intIndex;
}

public class TestPerstIndex {
    final static int nRecords = 100000;
    static int pagePoolSize = 32*1024*1024;

    static public void main(String[] args) {   
        Storage db = StorageFactory.getInstance().createStorage();
        db.open("testidx.dbs", pagePoolSize);
        Indices root = (Indices)db.getRoot();
        if (root == null) {
            root = new Indices();
            root.strIndex = db.createIndex(String.class, true);
            root.intIndex = db.createIndex(long.class, true);
            db.setRoot(root);
        }
        Index intIndex = root.intIndex;
        Index strIndex = root.strIndex;
        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);
            intIndex.put(new Key(rec.intKey), rec);               
            strIndex.put(new Key(rec.strKey), 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;
            Record rec1 = (Record)intIndex.get(new Key(key));
            Record rec2 = (Record)strIndex.get(new Key(Long.toString(key)));
            Assert.that(rec1 != null && rec1 == rec2);
        }
        System.out.println("Elapsed time for performing " + nRecords*2 + " index searches: "
                           + (System.currentTimeMillis() - start) + " milliseconds");
        start = System.currentTimeMillis();
        key = 1999;
        for (i = 0; i < nRecords; i++) {
            key = (3141592621L*key + 2718281829L) % 1000000007L;
            Record rec = (Record)intIndex.get(new Key(key));
            Record removed = (Record)intIndex.remove(new Key(key));
            Assert.that(removed == rec);
            strIndex.remove(new Key(Long.toString(key)));
            rec.deallocate();
        }

        System.out.println("Elapsed time for deleting " + nRecords + " records: "
                           + (System.currentTimeMillis() - start) + " milliseconds");
        db.close();
    }
}

 

 

标签 :



发表评论 发送引用通报