发表于:2006-06-20 09:13:00
楼主
转自:http://blog.csdn.net/johnlya
BerkeleyDB和eXtremeDB性能在LINUX下的比较
1、BerkeleyDB测试源程序:
#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
extern int getopt(int, char * const *, const char *);
#else
#include <unistd.h>
#endif
#include "db.h"
extern void __os_clock __P((DB_ENV *, u_int32_t *, u_int32_t *));
void usage __P((void));
struct db_time {
u_int32_t secs, usecs;
};
struct db_time start_time, end_time;
u_int32_t pagesize = 32 * 1024;
u_int bulkbufsize = 4 * 1024 * 1024;
u_int logbufsize = 8 * 1024 * 1024;
u_int cachesize = 32 * 1024 * 1024;
u_int datasize = 32;
u_int keysize = 8;
u_int numitems = 0;
FILE *fp;
char *progname;
void op_ds(u_int, int);
void op_ds_bulk(u_int, u_int *);
void op_tds(u_int, int, u_int32_t);
void res(char *, u_int);
void
res(char *msg, u_int ops)
{
double elapsed;
struct db_time v;
v.secs = end_time.secs - start_time.secs;
v.usecs = end_time.usecs - start_time.usecs;
if (start_time.usecs > end_time.usecs) {
v.secs--;
v.usecs += 1000000;
}
elapsed = v.secs + v.usecs / 1e6;
printf("%s\n\telapsed time: %f seconds : %g key/data pairs per sec\n",
msg, elapsed, ops / elapsed);
}
void
op_ds(u_int ops, int update)
{
char *letters = "abcdefghijklmnopqrstuvwxuz";
DB *dbp;
DBT key, data;
char *keybuf, *databuf;
DB_MPOOL_STAT *gsp;
(void)remove("a");
assert((keybuf = malloc(keysize)) != NULL);
assert((databuf = malloc(datasize)) != NULL);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = keybuf;
key.size = keysize;
memset(keybuf, 'a', keysize);
data.data = databuf;
data.size = datasize;
memset(databuf, 'b', datasize);
assert(db_create(&dbp, NULL, 0) == 0);
dbp->set_errfile(dbp, stderr);
assert(dbp->set_pagesize(dbp, pagesize) == 0);
assert(dbp->open(dbp, NULL, NULL, NULL, DB_BTREE, DB_CREATE, 0666) == 0);
dbp->dbenv->memp_stat(dbp->dbenv, &gsp, NULL, DB_STAT_CLEAR);
if (update) {
__os_clock(NULL, &start_time.secs, &start_time.usecs);
for (; ops > 0; --ops) {
keybuf[(ops % keysize)]&