#include #include #include #include int main(int argc, char **argv){ int dfunit = 0; if(argc > 1) dfunit = tcatoi(argv[1]); printf("dfunit: %d\n", dfunit); int rnum = 10000000; TCHDB *hdb = tchdbnew(); tchdbtune(hdb, rnum, 0, 1, 0); tchdbsetdfunit(hdb, dfunit); tchdbopen(hdb, "casket", HDBOWRITER | HDBOCREAT | HDBOTRUNC); double stime = tctime(); int range = rnum / 100; char vbuf[1024]; memset(vbuf, 0, sizeof(vbuf)); int mode = 0; int cnt = 0; for(int i = 0; i < rnum; i++){ int key = rand() % range; if(mode){ int vsiz = rand() % sizeof(vbuf); tchdbput(hdb, &key, sizeof(key), vbuf, vsiz); } else { tchdbout(hdb, &key, sizeof(key)); } if(cnt++ > 1000){ mode = !mode; cnt = 0; } } double etime = tctime(); printf("time: %.3f\n", etime - stime); printf("size: %ld\n", (long)tchdbfsiz(hdb)); tchdbclose(hdb); tchdbdel(hdb); return 0; }