⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcutest.c

📁 高性能嵌入式数据库在高并发的环境下使用最好是64位系统比较好
💻 C
📖 第 1 页 / 共 3 页
字号:
    if(i % 10 == 1){      for(int16_t j = 1; j <= 0x2000; j *= 2){        for(int16_t num = j - 1; num <= j + 1; num++){          int16_t nnum = TCHTOIS(num);          if(num != TCITOHS(nnum)) err = true;        }      }      for(int32_t j = 1; j <= 0x20000000; j *= 2){        for(int32_t num = j - 1; num <= j + 1; num++){          int32_t nnum = TCHTOIL(num);          if(num != TCITOHL(nnum)) err = true;          char buf[TCNUMBUFSIZ];          int step, nstep;          TCSETVNUMBUF(step, buf, num);          TCREADVNUMBUF(buf, nnum, nstep);          if(num != nnum || step != nstep) err = true;        }      }      for(int64_t j = 1; j <= 0x2000000000000000; j *= 2){        for(int64_t num = j - 1; num <= j + 1; num++){          int64_t nnum = TCHTOILL(num);          if(num != TCITOHLL(nnum)) err = true;          char buf[TCNUMBUFSIZ];          int step, nstep;          TCSETVNUMBUF64(step, buf, num);          TCREADVNUMBUF64(buf, nnum, nstep);          if(num != nnum || step != nstep) err = true;        }      }      char *bitmap = TCBITMAPNEW(100);      for(int j = 0; j < 100; j++){        if(j % 3 == 0) TCBITMAPON(bitmap, j);        if(j % 5 == 0) TCBITMAPOFF(bitmap, j);      }      for(int j = 0; j < 100; j++){        if(j % 5 == 0){          if(TCBITMAPCHECK(bitmap, j)) err = true;        } else if(j % 3 == 0){          if(!TCBITMAPCHECK(bitmap, j)) err = true;        }      }      TCBITMAPDEL(bitmap);      buf = tcmalloc(i / 8 + 2);      TCBITSTRM strm;      TCBITSTRMINITW(strm, buf);      for(int j = 0; j < i; j++){        int sign = j % 3 == 0 || j % 7 == 0;        TCBITSTRMCAT(strm, sign);      }      TCBITSTRMSETEND(strm);      int bnum = TCBITSTRMNUM(strm);      if(bnum != i) err = true;      TCBITSTRMINITR(strm, buf, bsiz);      for(int j = 0; j < i; j++){        int sign;        TCBITSTRMREAD(strm, sign);        if(sign != (j % 3 == 0 || j % 7 == 0)) err = true;      }      tcfree(buf);    }    if(rnum > 250 && i % (rnum / 250) == 0){      iputchar('.');      if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);    }  }  iprintf("time: %.3f\n", tctime() - stime);  if(err){    iprintf("error\n\n");    return 1;  }  iprintf("ok\n\n");  return 0;}/* perform wicked command */static int procwicked(int rnum){  iprintf("<Wicked Writing Test>\n  rnum=%d\n\n", rnum);  double stime = tctime();  TCMPOOL *mpool = tcmpoolglobal();  TCXSTR *xstr = myrand(2) > 0 ? tcxstrnew() : tcxstrnew2("hello world");  tcmpoolputxstr(mpool, xstr);  TCLIST *list = myrand(2) > 0 ? tclistnew() : tclistnew2(myrand(rnum) + rnum / 2);  tcmpoolputlist(mpool, list);  TCPTRLIST *ptrlist = myrand(2) > 0 ? tcptrlistnew() : tcptrlistnew2(myrand(rnum) + rnum / 2);  tcmpoolput(mpool, ptrlist, (void (*)(void*))tcptrlistdel);  TCMAP *map = myrand(2) > 0 ? tcmapnew() : tcmapnew2(myrand(rnum) + rnum / 2);  tcmpoolputmap(mpool, map);  TCTREE *tree = myrand(2) > 0 ? tctreenew() : tctreenew2(tctreecmpdecimal, NULL);  tcmpoolputtree(mpool, tree);  TCMDB *mdb = myrand(2) > 0 ? tcmdbnew() : tcmdbnew2(myrand(rnum) + rnum / 2);  tcmpoolput(mpool, mdb, (void (*)(void*))tcmdbdel);  TCNDB *ndb = myrand(2) > 0 ? tcndbnew() : tcndbnew2(tctreecmpdecimal, NULL);  tcmpoolput(mpool, ndb, (void (*)(void*))tcndbdel);  for(int i = 1; i <= rnum; i++){    char kbuf[RECBUFSIZ];    int ksiz = sprintf(kbuf, "%d", myrand(i));    char vbuf[RECBUFSIZ];    int vsiz = sprintf(vbuf, "%d", myrand(i));    char *tmp;    switch(myrand(70)){    case 0:      iputchar('0');      tcxstrcat(xstr, kbuf, ksiz);      break;    case 1:      iputchar('1');      tcxstrcat2(xstr, kbuf);      break;    case 2:      iputchar('2');      if(myrand(rnum / 100 + 1) == 0) tcxstrclear(xstr);      break;    case 3:      iputchar('3');      tcxstrprintf(xstr, "[%s:%d:%llu:%b:%llb]\n",                   kbuf, i, (long long)i * 65521, i, (unsigned long long)i * 65521);      break;    case 4:      iputchar('4');      tclistpush(list, kbuf, ksiz);      tcptrlistpush(ptrlist, tcmemdup(kbuf, ksiz));      break;    case 5:      iputchar('5');      tclistpush2(list, kbuf);      break;    case 6:      iputchar('6');      tmp = tcmemdup(kbuf, ksiz);      tclistpushmalloc(list, tmp, strlen(tmp));      break;    case 7:      iputchar('7');      if(myrand(10) == 0){        tcfree(tclistpop(list, &ksiz));        tcfree(tcptrlistpop(ptrlist));      }      break;    case 8:      iputchar('8');      if(myrand(10) == 0) tcfree(tclistpop2(list));      break;    case 9:      iputchar('9');      tclistunshift(list, kbuf, ksiz);      tcptrlistunshift(ptrlist, tcmemdup(kbuf, ksiz));      break;    case 10:      iputchar('A');      tclistunshift2(list, kbuf);      break;    case 11:      iputchar('B');      if(myrand(10) == 0){        tcfree(tclistshift(list, &ksiz));        tcfree(tcptrlistshift(ptrlist));      }      break;    case 12:      iputchar('C');      if(myrand(10) == 0) tcfree(tclistshift2(list));      break;    case 13:      iputchar('D');      tclistinsert(list, i / 10, kbuf, ksiz);      if(tcptrlistnum(ptrlist) > i / 10) tcptrlistinsert(ptrlist, i / 10, tcmemdup(kbuf, ksiz));      break;    case 14:      iputchar('E');      tclistinsert2(list, i / 10, kbuf);      break;    case 15:      iputchar('F');      if(myrand(10) == 0){        tcfree(tclistremove(list, i / 10, &ksiz));        tcfree(tcptrlistremove(ptrlist, i / 10));      }      break;    case 16:      iputchar('G');      if(myrand(10) == 0) tcfree(tclistremove2(list, i / 10));      break;    case 17:      iputchar('H');      tclistover(list, i / 10, kbuf, ksiz);      if(tcptrlistnum(ptrlist) > i / 10){        tcfree(tcptrlistval(ptrlist, i / 10));        tcptrlistover(ptrlist, i / 10, tcmemdup(kbuf, ksiz));      }      break;    case 18:      iputchar('I');      tclistover2(list, i / 10, kbuf);      break;    case 19:      iputchar('J');      if(myrand(rnum / 1000 + 1) == 0) tclistsort(list);      break;    case 20:      iputchar('K');      if(myrand(rnum / 1000 + 1) == 0) tclistsortci(list);      break;    case 21:      iputchar('L');      if(myrand(rnum / 1000 + 1) == 0) tclistlsearch(list, kbuf, ksiz);      break;    case 22:      iputchar('M');      if(myrand(rnum / 1000 + 1) == 0) tclistbsearch(list, kbuf, ksiz);      break;    case 23:      iputchar('N');      if(myrand(rnum / 100 + 1) == 0){        tclistclear(list);        for(int j = 0; j < tcptrlistnum(ptrlist); j++){          tcfree(tcptrlistval(ptrlist, j));        }        tcptrlistclear(ptrlist);      }      break;    case 24:      iputchar('O');      if(myrand(rnum / 100 + 1) == 0){        int dsiz;        char *dbuf = tclistdump(list, &dsiz);        tclistdel(tclistload(dbuf, dsiz));        tcfree(dbuf);      }      break;    case 25:      iputchar('P');      if(myrand(100) == 0){        if(myrand(2) == 0){          for(int j = 0; j < tclistnum(list); j++){            int rsiz;            tclistval(list, j, &rsiz);            tcptrlistval(ptrlist, j);          }        } else {          for(int j = 0; j < tclistnum(list); j++){            tclistval2(list, j);          }        }      }      break;    case 26:      iputchar('Q');      tcmapput(map, kbuf, ksiz, vbuf, vsiz);      tctreeput(tree, kbuf, ksiz, vbuf, vsiz);      break;    case 27:      iputchar('R');      tcmapput2(map, kbuf, vbuf);      tctreeput2(tree, kbuf, vbuf);      break;    case 28:      iputchar('S');      tcmapput3(map, kbuf, ksiz, vbuf, vsiz, vbuf, vsiz);      break;    case 29:      iputchar('T');      tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);      tctreeputkeep(tree, kbuf, ksiz, vbuf, vsiz);      break;    case 30:      iputchar('U');      tcmapputkeep2(map, kbuf, vbuf);      tctreeputkeep2(tree, kbuf, vbuf);      break;    case 31:      iputchar('V');      tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);      tctreeputcat(tree, kbuf, ksiz, vbuf, vsiz);      break;    case 32:      iputchar('W');      tcmapputcat2(map, kbuf, vbuf);      tctreeputcat2(tree, kbuf, vbuf);      break;    case 33:      iputchar('X');      if(myrand(10) == 0){        tcmapout(map, kbuf, ksiz);        tctreeout(tree, kbuf, ksiz);      }      break;    case 34:      iputchar('Y');      if(myrand(10) == 0){        tcmapout2(map, kbuf);        tctreeout2(tree, kbuf);      }      break;    case 35:      iputchar('Z');      tcmapget3(map, kbuf, ksiz, &vsiz);      tctreeget3(tree, kbuf, ksiz, &vsiz);      break;    case 36:      iputchar('a');      tcmapmove(map, kbuf, ksiz, true);      break;    case 37:      iputchar('b');      tcmapmove(map, kbuf, ksiz, false);      break;    case 38:      iputchar('c');      tcmapmove2(map, kbuf, true);      break;    case 39:      iputchar('d');      if(myrand(100) == 0){        tcmapiterinit(map);        if(myrand(2) == 0){          tctreeiterinit(tree);        } else {          tctreeiterinit2(tree, kbuf, ksiz);        }      }      break;    case 40:      iputchar('e');      tcmapiternext(map, &vsiz);      tctreeiternext(tree, &vsiz);      break;    case 41:      iputchar('f');      tcmapiternext2(map);      tctreeiternext2(tree);      break;    case 42:      iputchar('g');      if(myrand(100) == 0){        int anum;        switch(myrand(4)){        case 0:          tclistdel(tcmapkeys(map));          tclistdel(tctreekeys(tree));          break;        case 1:          tcfree(tcmapkeys2(map, &anum));          tcfree(tctreekeys2(tree, &anum));          break;        case 2:          tclistdel(tcmapvals(map));          tclistdel(tctreevals(tree));          break;        default:          tcfree(tcmapvals2(map, &anum));          tcfree(tctreevals2(tree, &anum));          break;        }      }      break;    case 43:      iputchar('h');      if(myrand(rnum / 100 + 1) == 0){        tcmapclear(map);        tctreeclear(tree);      }      break;    case 44:      iputchar('i');      if(myrand(20) == 0){        tcmapcutfront(map, myrand(10));        tctreecutfringe(tree, myrand(10));      }      break;    case 45:      iputchar('j');      if(myrand(rnum / 100 + 1) == 0){        int dsiz;        char *dbuf = tcmapdump(map, &dsiz);        tcfree(tcmaploadone(dbuf, dsiz, kbuf, ksiz, &vsiz));        tcmapdel(tcmapload(dbuf, dsiz));        tcfree(dbuf);        dbuf = tctreedump(tree, &dsiz);        tcfree(tctreeloadone(dbuf, dsiz, kbuf, ksiz, &vsiz));        tctreedel(tctreeload(dbuf, dsiz, tctreecmplexical, NULL));        tcfree(dbuf);      }      break;    case 46:      iputchar('k');      tcmdbput(mdb, kbuf, ksiz, vbuf, vsiz);      tcndbput(ndb, kbuf, ksiz, vbuf, vsiz);      break;    case 47:      iputchar('l');      tcmdbput2(mdb, kbuf, vbuf);      tcndbput2(ndb, kbuf, vbuf);      break;    case 48:      iputchar('m');      tcmdbputkeep(mdb, kbuf, ksiz, vbuf, vsiz);      tcndbputkeep(ndb, kbuf, ksiz, vbuf, vsiz);      break;    case 49:      iputchar('n');      tcmdbputkeep2(mdb, kbuf, vbuf);      tcndbputkeep2(ndb, kbuf, vbuf);      break;    case 50:      iputchar('o');      tcmdbputcat(mdb, kbuf, ksiz, vbuf, vsiz);      tcndbputcat(ndb, kbuf, ksiz, vbuf, vsiz);      break;    case 51:      iputchar('p');      tcmdbputcat2(mdb, kbuf, vbuf);      tcndbputcat2(ndb, kbuf, vbuf);      break;    case 52:      iputchar('q');      if(myrand(10) == 0){        tcmdbout(mdb, kbuf, ksiz);        tcndbout(ndb, kbuf, ksiz);      }      break;    case 53:      iputchar('r');      if(myrand(10) == 0){        tcmdbout2(mdb, kbuf);        tcndbout2(ndb, kbuf);      }      break;    case 54:      iputchar('s');      tcfree(tcmdbget(mdb, kbuf, ksiz, &vsiz));      tcfree(tcndbget(ndb, kbuf, ksiz, &vsiz));      break;    case 55:      iputchar('t');      tcfree(tcmdbget3(mdb, kbuf, ksiz, &vsiz));      tcfree(tcndbget3(ndb, kbuf, ksiz, &vsiz));      break;    case 56:      iputchar('u');      if(myrand(100) == 0){        tcmdbiterinit(mdb);        if(myrand(2) == 0){          tcndbiterinit(ndb);        } else {          tcndbiterinit2(ndb, kbuf, ksiz);        }      }      break;    case 57:      iputchar('v');      tcfree(tcmdbiternext(mdb, &vsiz));      tcfree(tcndbiternext(ndb, &vsiz));      break;    case 58:      iputchar('w');      tcfree(tcmdbiternext2(mdb));      tcfree(tcndbiternext2(ndb));      break;    case 59:      iputchar('x');      if(myrand(rnum / 100 + 1) == 0){        tcmdbvanish(mdb);        tcndbvanish(ndb);      }      break;    case 60:      iputchar('y');      if(myrand(200) == 0){        tcmdbcutfront(mdb, myrand(100));        tcndbcutfringe(ndb, myrand(100));      }      break;    case 61:      iputchar('+');      if(myrand(100) == 0) tcmpoolmalloc(mpool, 1);      break;    case 62:      iputchar('+');      if(myrand(100) == 0) tcmpoolxstrnew(mpool);      break;    case 63:      iputchar('+');      if(myrand(100) == 0) tcmpoollistnew(mpool);      break;    case 64:      iputchar('+');      if(myrand(100) == 0) tcmpoolmapnew(mpool);      break;    case 65:      iputchar('+');      if(myrand(100) == 0) tcmpooltreenew(mpool);      break;    default:      iputchar('@');      if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);      break;    }    if(i % 50 == 0) iprintf(" (%08d)\n", i);  }  if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);  for(int i = 0; i < tcptrlistnum(ptrlist); i++){    tcfree(tcptrlistval(ptrlist, i));  }  iprintf("time: %.3f\n", tctime() - stime);  iprintf("ok\n\n");  return 0;}// END OF FILE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -