Commit 70ba129f authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Create a scan benchmark. Addresses #820.

git-svn-id: file:///svn/tokudb@4093 c7de825b-a66e-492c-adef-691d508d4ae1
parent ab93683f
......@@ -74,3 +74,6 @@ PARGS =
ptest0 ptest1 ptest2 ptest3 ptest4 ptest5 ptest6 ptest7: db-benchmark-test-tokudb
./db-benchmark-test-tokudb --env $@.dir $(PARGS)
parallel-test-8: ptest0 ptest1 ptest2 ptest3 ptest4 ptest5 ptest6 ptest7
scanscan-tokudb: scanscan.c
$(CC) $(CFLAGS) $(TDB_CPPFLAGS) $(TDB_LDFLAGS) $< -o $@ -DDIRSUF=tokudb
/* Scan the bench.tokudb/bench.db over and over. */
#include <db.h>
#include <assert.h>
#include <string.h>
#include <sys/time.h>
DB_ENV *env;
DB *db;
DB_TXN *tid=0;
DBC *dbc;
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
const char *dbdir = "./bench." STRINGIFY(DIRSUF) "/"; /* DIRSUF is passed in as a -D argument to the compiler. */;
int env_open_flags = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOG|DB_INIT_LOCK;
char *dbfilename = "bench.db";
void setup (void) {
int r;
r = db_env_create(&env, 0); assert(r==0);
r = env->open(env, dbdir, env_open_flags, 0644); assert(r==0);
r = db_create(&db, env, 0); assert(r==0);
r = env->txn_begin(env, 0, &tid, 0); assert(r==0);
r = db->open(db, tid, dbfilename, NULL, DB_BTREE, 0, 0644); assert(r==0);
r = db->cursor(db, tid, &dbc, 0); assert(r==0);
}
void shutdown (void) {
int r;
r = dbc->c_close(dbc); assert(r==0);
r = db->close(db, 0); assert(r==0);
r = tid->commit(tid, 0); assert(r==0);
r = env->close(env, 0); assert(r==0);
}
double gettime (void) {
struct timeval tv;
int r = gettimeofday(&tv, 0);
assert(r==0);
return tv.tv_sec + 1e-6*tv.tv_usec;
}
void scanscan (void) {
int r;
long long totalbytes=0;
double prevtime = gettime();
int counter=0;
while (1) {
DBT k,v;
memset(&k, 0, sizeof(k));
memset(&v, 0, sizeof(v));
r = dbc->c_get(dbc, &k, &v, DB_NEXT);
if (r==DB_NOTFOUND) {
double thistime = gettime();
double tdiff = thistime-prevtime;
printf("Scan %lld bytes in %9.6fs at %9fMB/s\n", totalbytes, tdiff, 1e-6*totalbytes/tdiff);
r = dbc->c_get(dbc, &k, &v, DB_FIRST);
prevtime = thistime;
totalbytes=0;
counter++;
if (counter>0) return;
}
assert(r==0);
totalbytes += k.size + v.size;
}
}
int main (int argc, char *argv[]) {
argc=argc;
argv=argv;
setup();
scanscan();
shutdown();
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment