📄 tcumttest.c
字号:
targs[i].mdb = mdb; targs[i].ndb = tr ? ndb : NULL; targs[i].rnum = rnum; targs[i].rnd = rnd; targs[i].id = i; if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){ eprint("pthread_create"); targs[i].id = -1; err = true; } } for(int i = 0; i < tnum; i++){ if(targs[i].id == -1) continue; void *rv; if(pthread_join(threads[i], &rv) != 0){ eprint("pthread_join"); err = true; } else if(rv){ err = true; } } } if(tr){ iprintf("record number: %llu\n", (unsigned long long)tcndbrnum(ndb)); iprintf("size: %llu\n", (unsigned long long)tcndbmsiz(ndb)); } else { iprintf("record number: %llu\n", (unsigned long long)tcmdbrnum(mdb)); iprintf("size: %llu\n", (unsigned long long)tcmdbmsiz(mdb)); } tcndbdel(ndb); tcmdbdel(mdb); iprintf("time: %.3f\n", tctime() - stime); iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0;}/* perform typical command */static int proctypical(int tnum, int rnum, int bnum, bool tr, bool nc, int rratio){ iprintf("<Typical Access Test>\n tnum=%d rnum=%d bnum=%d tr=%d nc=%d rratio=%d\n\n", tnum, rnum, bnum, tr, nc, rratio); bool err = false; double stime = tctime(); TCMDB *mdb = (bnum > 0) ? tcmdbnew2(bnum) : tcmdbnew(); TCNDB *ndb = tcndbnew(); TARGTYPICAL targs[tnum]; pthread_t threads[tnum]; if(tnum == 1){ targs[0].mdb = mdb; targs[0].ndb = tr ? ndb : NULL; targs[0].rnum = rnum; targs[0].nc = nc; targs[0].rratio = rratio; targs[0].id = 0; if(threadtypical(targs) != NULL) err = true; } else { for(int i = 0; i < tnum; i++){ targs[i].mdb = mdb; targs[i].ndb = tr ? ndb : NULL; targs[i].rnum = rnum; targs[i].nc = nc; targs[i].rratio= rratio; targs[i].id = i; if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){ eprint("pthread_create"); targs[i].id = -1; err = true; } } for(int i = 0; i < tnum; i++){ if(targs[i].id == -1) continue; void *rv; if(pthread_join(threads[i], &rv) != 0){ eprint("pthread_join"); err = true; } else if(rv){ err = true; } } } if(tr){ iprintf("record number: %llu\n", (unsigned long long)tcndbrnum(ndb)); iprintf("size: %llu\n", (unsigned long long)tcndbmsiz(ndb)); } else { iprintf("record number: %llu\n", (unsigned long long)tcmdbrnum(mdb)); iprintf("size: %llu\n", (unsigned long long)tcmdbmsiz(mdb)); } tcndbdel(ndb); tcmdbdel(mdb); iprintf("time: %.3f\n", tctime() - stime); iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0;}/* thread the write function */static void *threadwrite(void *targ){ TCMDB *mdb = ((TARGCOMBO *)targ)->mdb; TCNDB *ndb = ((TARGCOMBO *)targ)->ndb; int rnum = ((TARGCOMBO *)targ)->rnum; bool rnd = ((TARGCOMBO *)targ)->rnd; int id = ((TARGCOMBO *)targ)->id; double stime = tctime(); if(id == 0) iprintf("writing:\n"); int base = id * rnum; for(int i = 1; i <= rnum; i++){ char buf[RECBUFSIZ]; int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i)); if(ndb){ tcndbput(ndb, buf, len, buf, len); } else { tcmdbput(mdb, buf, len, buf, len); } if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(id == 0) iprintf("time: %.3f\n", tctime() - stime); return NULL;}/* thread the read function */static void *threadread(void *targ){ TCMDB *mdb = ((TARGCOMBO *)targ)->mdb; TCNDB *ndb = ((TARGCOMBO *)targ)->ndb; int rnum = ((TARGCOMBO *)targ)->rnum; bool rnd = ((TARGCOMBO *)targ)->rnd; int id = ((TARGCOMBO *)targ)->id; double stime = tctime(); if(id == 0) iprintf("reading:\n"); int base = id * rnum; for(int i = 1; i <= rnum; i++){ char kbuf[RECBUFSIZ]; int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i) : i)); int vsiz; char *vbuf = ndb ? tcndbget(ndb, kbuf, ksiz, &vsiz) : tcmdbget(mdb, kbuf, ksiz, &vsiz); if(vbuf) tcfree(vbuf); if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(id == 0) iprintf("time: %.3f\n", tctime() - stime); return NULL;}/* thread the remove function */static void *threadremove(void *targ){ TCMDB *mdb = ((TARGCOMBO *)targ)->mdb; TCNDB *ndb = ((TARGCOMBO *)targ)->ndb; int rnum = ((TARGCOMBO *)targ)->rnum; bool rnd = ((TARGCOMBO *)targ)->rnd; int id = ((TARGCOMBO *)targ)->id; double stime = tctime(); if(id == 0) iprintf("removing:\n"); int base = id * rnum; for(int i = 1; i <= rnum; i++){ char buf[RECBUFSIZ]; int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i)); if(ndb){ tcndbout(ndb, buf, len); } else { tcmdbout(mdb, buf, len); } if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(id == 0) iprintf("time: %.3f\n", tctime() - stime); return NULL;}/* thread the typical function */static void *threadtypical(void *targ){ TCMDB *mdb = ((TARGTYPICAL *)targ)->mdb; TCNDB *ndb = ((TARGCOMBO *)targ)->ndb; int rnum = ((TARGTYPICAL *)targ)->rnum; bool nc = ((TARGTYPICAL *)targ)->nc; int rratio = ((TARGTYPICAL *)targ)->rratio; int id = ((TARGTYPICAL *)targ)->id; bool err = false; TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL; int base = id * rnum; int mrange = tclmax(50 + rratio, 100); for(int i = 1; !err && i <= rnum; i++){ char buf[RECBUFSIZ]; int len = sprintf(buf, "%08d", base + myrandnd(i)); int rnd = myrand(mrange); if(rnd < 10){ if(ndb){ tcndbput(ndb, buf, len, buf, len); } else { tcmdbput(mdb, buf, len, buf, len); } if(map) tcmapput(map, buf, len, buf, len); } else if(rnd < 15){ if(ndb){ tcndbputkeep(ndb, buf, len, buf, len); } else { tcmdbputkeep(mdb, buf, len, buf, len); } if(map) tcmapputkeep(map, buf, len, buf, len); } else if(rnd < 20){ if(ndb){ tcndbputcat(ndb, buf, len, buf, len); } else { tcmdbputcat(mdb, buf, len, buf, len); } if(map) tcmapputcat(map, buf, len, buf, len); } else if(rnd < 30){ if(ndb){ tcndbout(ndb, buf, len); } else { tcmdbout(mdb, buf, len); } if(map) tcmapout(map, buf, len); } else if(rnd < 31){ if(myrand(10) == 0) tcmdbiterinit(mdb); for(int j = 0; !err && j < 10; j++){ int ksiz; char *kbuf = ndb ? tcndbiternext(ndb, &ksiz) : tcmdbiternext(mdb, &ksiz); if(kbuf) tcfree(kbuf); } } else { int vsiz; char *vbuf = ndb ? tcndbget(ndb, buf, len, &vsiz) : tcmdbget(mdb, buf, len, &vsiz); if(vbuf){ if(map){ int msiz; const char *mbuf = tcmapget(map, buf, len, &msiz); if(msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint("(validation)"); err = true; } } tcfree(vbuf); } else { if(map && tcmapget(map, buf, len, &vsiz)){ eprint("(validation)"); err = true; } } } if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(map){ tcmapiterinit(map); int ksiz; const char *kbuf; while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){ int vsiz; char *vbuf = ndb ? tcndbget(ndb, kbuf, ksiz, &vsiz) : tcmdbget(mdb, kbuf, ksiz, &vsiz); if(vbuf){ int msiz; const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz); if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint("(validation)"); err = true; } tcfree(vbuf); } else { eprint("(validation)"); err = true; } } tcmapdel(map); } return err ? "error" : NULL;}// END OF FILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -