Java代码测试数据库性能_JDBM纯Java数据库性能测试评估

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();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值