<< How to read all the data from an Lucene index? | 首页 | Jisp Java Database Performance >>

JDBM纯Java数据库性能测试评估

JDBM性能测试评估,最近想选择一个轻量、可伸缩、高性能的嵌入式数据库,所以对JDBM 纯Java数据库进行了测试评估。从结果看来JDBM还是挺不错的,和db4o,Perst,Berkeley DB是一个级别的,每秒能插入10000个对象,10000次对象查询能在1秒内完成,删除10000个对象也大约能在1-2秒内完成。看来表现最差的JISP,insert、search、delete差不多都需要30秒。

版本:

jdbm-unspecified.jar(1.0)

结果:

Elapsed time for inserting 100000 records: 12282 milliseconds
Elapsed time for performing 100000 index searches: 7125 milliseconds
Elapsed time for deleting 100000 records: 16203 milliseconds

代码:


import java.util.Properties;

import jdbm.RecordManager;
import jdbm.RecordManagerFactory;
import jdbm.helper.StringComparator;
import jdbm.btree.BTree;


public class FamousPeople {

    static String DATABASE = "people";
    static String BTREE_NAME = "FamousPeople";

    /**
     * Example main entrypoint.
     */
    public static void main( String[] args ) {
    
     
        RecordManager recman;
        long          recid;

        BTree         tree;
        Properties    props;

        props = new Properties();

        try {
      // open database and setup an object cache
            recman = RecordManagerFactory.createRecordManager( DATABASE, props );

            // try to reload an existing B+Tree
            recid = recman.getNamedObject( BTREE_NAME );
            if ( recid != 0 ) {
                tree = BTree.load( recman, recid );
                System.out.println( "Reloaded existing BTree with " + tree.size()
                                    + " famous people." );
            } else {
                // create a new B+Tree data structure and use a StringComparator
                // to order the records based on people's name.
                tree = BTree.createInstance( recman, new StringComparator() );
                recman.setNamedObject( BTREE_NAME, tree.getRecid() );
                System.out.println( "Created a new empty BTree" );
            }

            // insert people with their respective occupation
            System.out.println();
            long key = 1999;
            int nRecords=100000;
            long start=System.currentTimeMillis();
            for (int i = 0; i < nRecords; i++) {
                key = (3141592621L*key + 2718281829L) % 1000000007L;
                tree.insert( key+"", Long.toString(key), false );
            }           
            System.out.println("Elapsed time for inserting " + nRecords + " records: "
                    + (System.currentTimeMillis() - start) + " milliseconds");

           
            key = 1999;
            start=System.currentTimeMillis();
            for (int i = 0; i < nRecords; i++) {
                key = (3141592621L*key + 2718281829L) % 1000000007L;
                tree.find( key+"" );
            }   
            System.out.println("Elapsed time for performing " + nRecords + " index searches: "
                    + (System.currentTimeMillis() - start) + " milliseconds");
           
            key = 1999;
            start=System.currentTimeMillis();
            for (int i = 0; i < nRecords; i++) {
                key = (3141592621L*key + 2718281829L) % 1000000007L;
                tree.remove( key+"" );
            }           
            System.out.println("Elapsed time for deleting " + nRecords + " records: "
                    + (System.currentTimeMillis() - start) + " milliseconds");

            // make the data persistent in the database
            recman.commit();

            recman.close();
        } catch ( Exception except ) {
            except.printStackTrace();
        }
    }


}

 


 

标签 :



发表评论 发送引用通报