int main(int argc, char **argv) { int i = 0, id = 0, n = 0, x = 0, count = 50000000; char line[FILE_LINE_MAX], *p = NULL; unsigned short *list = NULL; unsigned char digest[MD5_LEN]; MMKEY *mmkey = NULL; void *timer = NULL; if((mmkey = mmkey_init("/tmp/test.mmkey"))) { TIMER_INIT(timer); for(i = 1; i <= count; i++) { n = sprintf(line, "http://www.demo.com/%d.html", i); md5(line, n, digest); list = (unsigned short *)digest; id = mmkey_xadd(mmkey, list, 4); /* if(mmkey_get(mmkey, list, 4) != i) { fprintf(stderr, "NoFound key:%02X%02X%02X%02X id:%d\n", list[0],list[1],list[2],list[3], i); _exit(-1); } */ } TIMER_SAMPLE(timer); fprintf(stdout, "%s::%d insert:%d time:%lld\n", __FILE__,__LINE__, count, PT_LU_USEC(timer)); TIMER_CLEAN(timer); mmkey->clean(mmkey); } }
int main(int argc, char **argv) { int i = 0, rootid = 0, id = 0, j = 0, old = 0, data = 0, n = 0, count = 50000000; unsigned char digest[MD5_LEN]; void *mmtree = NULL; void *timer = NULL; char line[1024]; int64_t key = 0; if((mmtree = mmtree64_init("/tmp/test.mmtree64"))) { rootid = mmtree64_new_tree(mmtree); TIMER_INIT(timer); for(j = 1; j <= count; j++) { n = sprintf(line, "http://www.demo.com/%d.html", j); md5(line, n, digest); key = *((int64_t *)digest); old = -1; data = j; id = mmtree64_insert(mmtree, rootid, key, data, &old); if(old > 0 || id <= 0) { fprintf(stdout, "%d:{id:%d key:%d rootid:%d old:%d}\n", j, id, key, rootid, old); } } TIMER_SAMPLE(timer); fprintf(stdout, "%s::%d insert:%d time:%lld\n", __FILE__,__LINE__, count, PT_LU_USEC(timer)); for(j = 1; j <= count; j++) { n = sprintf(line, "http://www.demo.com/%d.html", j); md5(line, n, digest); key = *((int64_t *)digest); old = -1; data = j; id = mmtree64_try_insert(mmtree, rootid, key, data, &old); if(old > 0 && old != j) { fprintf(stdout, "%d:{id:%d key:%d rootid:%d old:%d}\n", j, id, key, rootid, old); _exit(-1); } } TIMER_SAMPLE(timer); fprintf(stdout, "%s::%d try_insert:%d time:%lld\n", __FILE__,__LINE__, count, PT_LU_USEC(timer)); TIMER_CLEAN(timer); mmtree64_close(mmtree); } }
int main() { int i = 0, key = 0, count = 10000, ret = 0; void *map = NULL, *timer = NULL; if((map = IMMX_INIT())) { TIMER_INIT(timer); while(i++ < count) { key = random()%count; IMMX_ADD(map, key); //if(olddp)fprintf(stdout, "old[%d:%08x]\n", key, olddp); } TIMER_SAMPLE(timer); fprintf(stdout, "insert %d nodes count:%d free:%d total:%d time used:%lld\n", count, PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer)); i = 0; while(i++ < count) { key = random()%count; ret = 0; IMMX_GET(map, key, ret); if(ret) fprintf(stdout, "%d:[%d]\n", key, ret); } TIMER_SAMPLE(timer); fprintf(stdout, "get %d nodes count:%d free:%d total:%d time used:%lld\n", count, PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer)); do { ret = 0; IMMX_POP_MIN(map, key, ret); if(ret) fprintf(stdout, "%d:[%d]\n", key, ret); }while(IMX_ROOT(map)); TIMER_SAMPLE(timer); fprintf(stdout, "pop min(%d) node count:%d free:%d total:%d time used:%lld\n", count, PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer)); i = 0; while(i < count) { key = random()%count; IMMX_ADD(map, key); ++i; } TIMER_SAMPLE(timer); fprintf(stdout, "insert %d nodes count:%d free:%d total:%d time used:%lld\n", count, PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer)); do { ret = 0; IMMX_POP_MAX(map, key, ret); if(ret) fprintf(stdout, "%d:[%d]\n", key, ret); }while(IMX_ROOT(map)); TIMER_SAMPLE(timer); fprintf(stdout, "pop max(%d) nodes count:%d free:%d total:%d time used:%lld\n", count, PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer)); TIMER_SAMPLE(timer); TIMER_CLEAN(timer); IMMX_CLEAN(map); } }
/* sock_dgram /UCP handler */ void ev_udp_handler(int fd, int ev_flags, void *arg) { int i = 0, n = 0, nevdnsbuf = 0, reqfd = -1, respfd = -1; unsigned char evdnsbuf[EVDNS_BUF_SIZE], *p = NULL; char ip[DNS_IP_MAX]; HOSTENT hostent = {0}; if(ev_flags & E_READ) { //if( ( n = recvfrom(fd, buffer[fd], EV_BUF_SIZE, 0, (struct sockaddr *)&rsa, &rsa_len)) > 0 ) if( ( n = read(fd, buffer[fd], EV_BUF_SIZE)) > 0 ) { TIMER_SAMPLE(timer); evdns_parse_reply((unsigned char *)buffer[fd], n, &hostent); if(hostent.naddrs > 0) { fprintf(stdout, "time:%lld QID:%d name:%s nalias:%d naddrs:%d\n", PT_LU_USEC(timer), hostent.qid, hostent.name, hostent.nalias, hostent.naddrs); for(i = 0; i < hostent.nalias; i++) { fprintf(stdout, "alias%d:%s\n", i, hostent.alias[i]); } for(i = 0; i < hostent.naddrs; i++) { p = (unsigned char *)&(hostent.addrs[i]); sprintf(ip, "%d.%d.%d.%d", *p, *(p+1), *(p+2), *(p+3)); fprintf(stdout, "ip[%d] [%d][%s:][%d]\n", i, hostent.addrs[i], ip, inet_addr(ip)); } fprintf(stdout, "\r\n"); } if((respfd = open("/tmp/dns.response", O_CREAT|O_RDWR, 0644)) > 0) { if(write(respfd, buffer[fd], n) <= 0)_exit(-1); close(respfd); respfd = -1; _exit(-1); } SHOW_LOG("Read %d bytes from %d", n, fd); buffer[fd][n] = 0; SHOW_LOG("Updating event[%p] on %d ", &events[fd], fd); event_add(&events[fd], E_WRITE); } else { if(n < 0 ) FATAL_LOG("Reading from %d failed, %s", fd, strerror(errno)); goto err; } } if(ev_flags & E_WRITE) { nevdnsbuf = evdns_make_query(domain, 1, 1, 1, 1, evdnsbuf); if((reqfd = open("/tmp/dns.query", O_CREAT|O_RDWR, 0644)) > 0) { if(write(reqfd, evdnsbuf, nevdnsbuf) <= 0)_exit(-1); close(reqfd); reqfd = -1; } //if( (n = write(fd, buffer[fd], strlen(buffer[fd])) ) > 0 ) if((n = write(fd, evdnsbuf, nevdnsbuf)) > 0) { SHOW_LOG("Wrote %d bytes via %d", n, fd); TIMER_RESET(timer); } else { if(n < 0) FATAL_LOG("Wrote data via %d failed, %s", fd, strerror(errno)); goto err; } event_del(&events[fd], E_WRITE); } return ; err: { event_destroy(&events[fd]); shutdown(fd, SHUT_RDWR); close(fd); SHOW_LOG("Connection %d closed", fd); } }
int main(int argc, char **argv) { unsigned char url[HTTP_URL_MAX], *p = NULL; FILE *fp = NULL; unsigned char key[MD5_LEN]; void *urlmap = NULL, *dp = NULL, *olddp = NULL; long n = 0, id = 0; void *timer = NULL; long long total = 0; char *file = NULL; if(argc < 2) { fprintf(stderr, "Usage:%s file\n", argv[0]); _exit(-1); } file = argv[1]; if(file && (fp = fopen(file, "r"))) { KVMAP_INIT(urlmap); if(urlmap) { TIMER_INIT(timer); while(fgets((char *)url, HTTP_URL_MAX, fp)) { //fprintf(stdout, "%s", url); //memset(url, 0, HTTP_URL_MAX); //continue; //continue; p = url; while(*p != '\0' && *p != '\r' && *p != '\n') ++p; n = p - url; //n = strlen(url) - 1; //if(n == 0) {fprintf(stdout, "URL:%d\n", id); continue;} md5(url, n, key); dp = (void *)++id; olddp = NULL; TIMER_SAMPLE(timer); KVMAP_ADD(urlmap, key, dp, olddp); TIMER_SAMPLE(timer); total += PT_LU_USEC(timer); if(olddp) { fprintf(stdout, "Repeat:%ld vs %ld:%d:%s\n", (long)dp, (long)olddp, n, url); } else { //fprintf(stdout, "%ld:%s", id, url); } memset(url, 0, HTTP_URL_MAX); } if(id > 0) { fprintf(stdout, "add %d sizeof(KVNODE):%d avg:%g microsecond(s)\n", id, sizeof(KVNODE), (double )(total/id)); } TIMER_CLEAN(timer); KVMAP_CLEAN(urlmap); } fclose(fp); } while(1) sleep(1); }
//rm -rf /tmp/1.idx* && gcc -O2 -o lkv lkv.c -DLKV_TEST -DTEST_KV -DHAVE_PTHREAD -lpthread && ./lkv int main() { LKV *lkv = NULL; int i = 0, j = 0, n = 0, total = 0, no = 0, stat[MASK], stat2[MASK], v = 0, num = 1000000, base = 60000000; int64_t val = 0, from = 0, to = 0, *res = NULL, all_mask = 200000; int64_t inputs[256], nos[256], last[256], tall[200000]; int64_t all = 0; time_t stime = 0, etime = 0; void *timer = NULL; if((lkv = lkv_init("/tmp/1.idx"))) { res = (int64_t *)calloc(base, sizeof(int64_t)); TIMER_INIT(timer); #ifdef TEST_KV TIMER_RESET(timer); for(i = 0; i < num; i++) { no = random()%base; LKV_SET(lkv, no, i); } TIMER_SAMPLE(timer); fprintf(stdout, "set(%d) time used:%lld\n", num, PT_LU_USEC(timer)); TIMER_RESET(timer); for(i = 0; i < num; i++) { no = random()%base; v = LKV_GET(lkv, no); } fprintf(stdout, "get(%d) time used:%lld\n", num, PT_LU_USEC(timer)); #endif #ifdef TEST_RFROM lkv_set(lkv, 1, 22); lkv_set(lkv, 2, 25); lkv_set(lkv, 3, 20); lkv_set(lkv, 4, 13); lkv_set(lkv, 6, 22); n = lkv_rangefrom(lkv, 21, NULL); fprintf(stdout, "rangefrom(21) => %d\n", n); #endif #ifdef TEST_DEB /* n = lkv_in(lkv, 16615, NULL); fprintf(stdout, "16615:%d\n", n); */ n = 0; for(i = 0; i < lkv->state->count; i++) { /* if(lkv->slots[i].min <= 26650 && lkv->slots[i].max >= 26650) { fprintf(stdout, "%d:[min:%d max:%d]\n", i, lkv->slots[i].min, lkv->slots[i].max); } */ n+= lkv->slots[i].count; } fprintf(stdout, "total:%d\n", n); #endif #ifdef TEST_IN for(i = 0; i < all_mask; i++) { tall[i] = 0; } for(i = 80000000; i > 0; i--) { no = (rand()%all_mask); lkv_set(lkv, i, no); tall[no]++; } for(i = 0; i < all_mask; i++) { n = lkv_in(lkv, i, NULL); if(n != tall[i]) fprintf(stdout, "%d:[%d/%d]\n", i, n, tall[i]); } #endif #ifdef TEST_ALL for(i = 0; i < all_mask; i++) { tall[i] = 0; } for(i = 80000000; i > 0; i--) { no = (rand()%all_mask); lkv_set(lkv, i, no); tall[no]++; } no = (rand()%all_mask); total = 0;for(i = no; i < all_mask; i++) total += tall[i]; fprintf(stdout, "rangefrom(%d):%d/%d\n", no, lkv_rangefrom(lkv, no, NULL), total); total = 0;for(i = 0; i <= no; i++) total += tall[i]; fprintf(stdout, "rangeto(%d):%d/%d\n", no, lkv_rangeto(lkv, no, NULL), total); from = (rand()%all_mask); to = (rand()%all_mask); if(from > to){from += to; to = from - to; from = from - to;} total = 0;for(i = from; i <= to; i++) total += tall[i]; fprintf(stdout, "range(%d,%d):%d/%d\n", from, no, lkv_range(lkv, from, to, NULL), total); for(i = 0; i < all_mask; i++) { n = lkv_in(lkv, i, NULL); if(n != tall[i]) fprintf(stdout, "%d:[%d/%d]\n", i, n, tall[i]); } #endif #ifdef TEST_INS //fprintf(stdout, "sizeof(stat):%d\n", sizeof(stat)); memset(stat, 0, sizeof(stat)); memset(stat2, 0, sizeof(stat2)); srand(time(NULL)); n = 256; for(i = 0; i < n; i++) { no = (rand()%MASK); nos[i] = no; if((i % 3) == 0) inputs[i] = no * -1; else inputs[i] = no; } TIMER_RESET(timer); for(i = 1; i < 20000000; i++) { j = (rand()%n); val = inputs[j]; no = nos[j]; stat[no]++; lkv_set(lkv, i, val); last[j] = i; } TIMER_SAMPLE(timer); fprintf(stdout, "set() 40000000 data, time used:%lld\n", PT_LU_USEC(timer)); TIMER_RESET(timer); for(i = 0; i < n; i++) { lkv_del(lkv, last[i]); } TIMER_SAMPLE(timer); fprintf(stdout, "del() time used:%lld\n", PT_LU_USEC(timer)); TIMER_RESET(timer); for(i = 0; i < n; i++) { val = inputs[i]; no = nos[i]; stat2[no] = lkv_in(lkv, val, res); } TIMER_SAMPLE(timer); fprintf(stdout, "in() time used:%lld\n", PT_LU_USEC(timer)); TIMER_RESET(timer); total = lkv_ins(lkv, inputs, n, NULL); TIMER_SAMPLE(timer); fprintf(stdout, "ins(keys, NULL) total:%d time used:%lld\n", total, PT_LU_USEC(timer)); TIMER_RESET(timer); total = lkv_ins(lkv, inputs, n, res); TIMER_SAMPLE(timer); fprintf(stdout, "ins(keys, res:%p) total:%d time used:%lld\n", res, total, PT_LU_USEC(timer)); for(i = 0; i < n; i++) { j = nos[i]; if(stat[j] != stat2[j]) fprintf(stdout, "%d:%d/%d::%d\n", j, stat[j], stat2[j], inputs[i]); } #ifdef OUT_ALL for(i = 0; i < total; i++) { fprintf(stdout, "%d:%d\n", i, res[i]); } #endif #endif /* for(i = 0; i < lkv->state->count; i++) { fprintf(stdout, "%d:{min:%d max:%d}(%d)\n", i, lkv->slots[i].min, lkv->slots[i].max, lkv->slots[i].count); } */ #ifdef TEST_RANGEFILTER lkv_set(lkv, 1, 1234567); lkv_set(lkv, 2, 1567890); fprintf(stdout, "rangefrom():%d\n", lkv_rangefrom(lkv, 1569000, NULL)); fprintf(stdout, "rangeto():%d\n", lkv_rangeto(lkv, 1111111, NULL)); fprintf(stdout, "range():%d\n", lkv_range(lkv, 1111111, 1400000, NULL)); #endif #ifdef TEST_RANGE srand(time(NULL)); TIMER_RESET(timer); for(i = 1; i < 40000000; i++) { val = 1356969600 + (rand()%31536000); lkv_set(lkv, i, val); } TIMER_SAMPLE(timer); fprintf(stdout, "set() 40000000 timestamps, time used:%lld\n", PT_LU_USEC(timer)); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { val = 1356969600 + (rand()%31536000); all += lkv_rangefrom(lkv, val, res); } TIMER_SAMPLE(timer); fprintf(stdout, "rangefrom() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer)); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { val = 1356969600 + (rand()%31536000); all += lkv_rangeto(lkv, val, res); } TIMER_SAMPLE(timer); fprintf(stdout, "rangeto() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer)); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { from = 1356969600 + (rand()%31536000); to = from + rand()%31536000; all += lkv_range(lkv, from, to, res); } TIMER_SAMPLE(timer); fprintf(stdout, "range(%p) 1000 times total:%lld, time used:%lld\n", res, (long long int)all, PT_LU_USEC(timer)); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { from = 1356969600 + (rand()%31536000); to = from + rand()%31536000; all += lkv_range(lkv, from, to, NULL); } TIMER_SAMPLE(timer); fprintf(stdout, "range(null) 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer)); #endif lkv_close(lkv); TIMER_CLEAN(timer); free(res); } }
int main(int argc, char **argv) { int i = 0, k = 0, x = 0, mid = 0, qid = 0, port = 0, flag = 0, dbport = 0, isdaemon = 0, isout = 0, packetid = 0, ret = -1, from = 0, to = 0; char tmp[XX_BUF_SIZE], url[XX_URL_MAX],*ip = NULL, *dbhost = NULL, block[XX_PACKET_MAX * sizeof(int64_t)], ch = 0; int64_t *list = NULL, key = 0, rand = 0; unsigned char digest[MD5_LEN]; BJSON request = {0}; void *timer = NULL; BREC record = {0}; MTASK mtask = {0}; pid_t pid = 0; DBASE db = {0}; /* get configure file */ while((ch = getopt(argc, argv, "h:p:m:q:i:x:n:c:f:t:od")) != -1) { switch(ch) { case 'h': ip = optarg; break; case 'p': port = atoi(optarg); break; case 'm': mid = atoi(optarg); break; case 'q': qid = atoi(optarg); break; case 'i': dbhost = optarg; break; case 'x': dbport = atoi(optarg); break; case 'f': from = atoi(optarg); break; case 't': to = atoi(optarg); break; case 'o': isout = 1; break; case 'd': isdaemon = 1; break; default: break; } } if(ip == NULL || port <= 0 || (qid == 0 && mid == 0) || dbhost == NULL || dbport <= 0) { fprintf(stderr, "Usage:%s -h qtask_host -p qtask_port -m commitid -q queueid " "-i dbhost -x dbport -f from -t to -o output -d is_working_daemon\n", argv[0]); _exit(-1); } /* daemon */ if(isdaemon) { pid = fork(); switch (pid) { case -1: perror("fork()"); exit(EXIT_FAILURE); break; case 0: /* child process */ if(setsid() == -1) exit(EXIT_FAILURE); break; default:/* parent */ _exit(EXIT_SUCCESS); break; } } if(mtask_set(&mtask, ip, port, mid, qid) == 0 && mtask_connect(&mtask) == 0) { if(dbase_set(&db, dbhost, dbport) != 0 || dbase_connect(&db) != 0) { fprintf(stderr, "connect to db[%s:%d] failed, %s\n", dbhost, dbport, strerror(errno)); _exit(-1); } list = (int64_t *)block; //sprintf(ns, "%s.%s", dbname, collection); TIMER_INIT(timer); BJSON_INIT(request); k = from; if(to <= 0) to = from + 10000000; do { TIMER_SAMPLE(timer); rand = random(); flag = 0; //if((rand%33) == 0) flag = MTASK_TO_QHEAD; x = 0; while(x < XX_PACKET_MAX) { //fprintf(stdout, "%s::%d ns:%s OK\n", __FILE__, __LINE__, ns); sprintf(url, "http://demo.com/%d.html", ++k); memset(digest, 0, MD5_LEN); md5((unsigned char *)url, strlen(url), digest); key = *((int64_t *)digest); sprintf(tmp, "title %d content %d comment %d", k, k, k); brequest_reset(&request); bjson_start(&request); bjson_append_long(&request, "id", key); bjson_new_object(&request, "property"); bjson_append_int(&request, "status", 1); bjson_append_int(&request, "crc", crc32(tmp, strlen(tmp))); bjson_append_int(&request, "slevel", 1); bjson_append_long(&request, "category", (int64_t)1 << (rand%64)); bjson_append_double(&request, "rank", 1.0); bjson_finish_object(&request); //fprintf(stdout, "%s::%d key:%lld\n", __FILE__, __LINE__, key); bjson_new_object(&request, "text_index"); sprintf(tmp, "title %d", k); bjson_append_string(&request, "title", tmp); sprintf(tmp, "content %d", k); bjson_append_string(&request, "content", tmp); sprintf(tmp, "comment %d", k); bjson_append_string(&request, "comment", tmp); bjson_finish_object(&request); //fprintf(stdout, "%s::%d key:%lld\n", __FILE__, __LINE__, key); bjson_new_object(&request, "int_index"); bjson_append_int(&request, "0", rand/3); bjson_append_int(&request, "1", rand/9); bjson_append_int(&request, "2", rand/31); bjson_finish_object(&request); bjson_new_object(&request, "long_index"); bjson_append_long(&request, "0", rand/2); bjson_append_long(&request, "1", rand/7); bjson_append_long(&request, "2", rand/21); bjson_finish_object(&request); bjson_new_object(&request, "double_index"); bjson_append_double(&request, "0", (double)rand/(double)33); bjson_append_double(&request, "1", (double)rand/(double)53); bjson_append_double(&request, "2", (double)rand/(double)73); bjson_finish_object(&request); bjson_new_object(&request, "display"); bjson_append_string(&request, "url", url); sprintf(tmp, "http://demo.com/%d.jpg", k); bjson_append_string(&request, "img", tmp); bjson_finish_object(&request); bjson_finish(&request); if(isout) { record.data = request.data; record.ndata = request.current; bjson_json(&record, tmp); fprintf(stdout, "json:%s\n", tmp); } if((ret = dbase_set_record(&db, key, &request)) < 0) { fprintf(stderr, "set_data(%lld) ndata:%d failed, ret:%d\n", (long long)key, request.current, ret); _exit(-1); } //_exit(-1); list[x++] = key; } if(isout) { TIMER_SAMPLE(timer); fprintf(stdout, "db-time-used:%lld\n", PT_LU_USEC(timer)); TIMER_SAMPLE(timer); } if((packetid = mtask_push(&mtask, flag, block, sizeof(int64_t) * XX_PACKET_MAX)) >= 0) { if(isout) { TIMER_SAMPLE(timer); fprintf(stdout, "mtask-time-used:%lld\n", PT_LU_USEC(timer)); fprintf(stdout, "1:{%d:{packetid:%d}}\n", i, packetid); } ++i; } else { fprintf(stderr, "push mtask failed, %s\n", strerror(errno)); sleep(1); } }while(k < to); bjson_clean(&request); dbase_close(&db); mtask_close(&mtask); TIMER_CLEAN(timer); } return 0; }
//gcc -o dmap dmap.c -DDMAP_TEST -DTEST_INS -DHAVE_PTHREAD -lpthread && ./dmap int main() { DMAP *dmap = NULL; int i = 0, j = 0, n = 0, total = 0, no = 0, stat[MASK], stat2[MASK]; double val = 0, from = 0, to = 0, *res = NULL; double inputs[256], nos[256], last[256]; double all = 0; time_t stime = 0, etime = 0; void *timer = NULL; if((dmap = dmap_init("/tmp/1.idx"))) { res = (double *)calloc(60000000, sizeof(double)); TIMER_INIT(timer); #ifdef TEST_INS //fprintf(stdout, "sizeof(stat):%d\n", sizeof(stat)); memset(stat, 0, sizeof(stat)); memset(stat2, 0, sizeof(stat2)); srand(time(NULL)); n = 256; for(i = 0; i < n; i++) { no = (rand()%MASK); nos[i] = no; if((i % 3) == 0) inputs[i] = no * -1; else inputs[i] = no; } TIMER_RESET(timer); for(i = 1; i < 20000000; i++) { j = (rand()%n); val = inputs[j]; no = nos[j]; stat[no]++; dmap_set(dmap, i, val); last[j] = i; } TIMER_SAMPLE(timer); fprintf(stdout, "set() 40000000 data, time used:%lld\n", PT_LU_USEC(timer)); TIMER_RESET(timer); for(i = 0; i < n; i++) { dmap_del(dmap, last[i]); } TIMER_SAMPLE(timer); fprintf(stdout, "del() time used:%lld\n", PT_LU_USEC(timer)); TIMER_RESET(timer); for(i = 0; i < n; i++) { val = inputs[i]; no = nos[i]; stat2[no] = dmap_in(dmap, val, res); } TIMER_SAMPLE(timer); fprintf(stdout, "in() time used:%lld\n", PT_LU_USEC(timer)); TIMER_RESET(timer); total = dmap_ins(dmap, inputs, n, NULL); TIMER_SAMPLE(timer); fprintf(stdout, "ins(keys, NULL) total:%d time used:%lld\n", total, PT_LU_USEC(timer)); TIMER_RESET(timer); total = dmap_ins(dmap, inputs, n, res); TIMER_SAMPLE(timer); fprintf(stdout, "ins(keys, res:%p) total:%d time used:%lld\n", res, total, PT_LU_USEC(timer)); for(i = 0; i < n; i++) { j = nos[i]; if(stat[j] != stat2[j]) fprintf(stdout, "%d:%d/%d::%d\n", j, stat[j], stat2[j], inputs[i]); } #ifdef OUT_ALL for(i = 0; i < total; i++) { fprintf(stdout, "%d:%d\n", i, res[i]); } #endif #endif /* for(i = 0; i < dmap->state->count; i++) { fprintf(stdout, "%d:{min:%d max:%d}(%d)\n", i, dmap->slots[i].min, dmap->slots[i].max, dmap->slots[i].count); } */ #ifdef TEST_RANGEFILTER dmap_set(dmap, 1, 1234567); dmap_set(dmap, 2, 1567890); fprintf(stdout, "rangefrom():%d\n", dmap_rangefrom(dmap, 1569000, NULL)); fprintf(stdout, "rangeto():%d\n", dmap_rangeto(dmap, 1111111, NULL)); fprintf(stdout, "range():%d\n", dmap_range(dmap, 1111111, 1600000, NULL)); #endif #ifdef TEST_RANGE srand(time(NULL)); TIMER_RESET(timer); for(i = 1; i < 40000000; i++) { val = 1356969600 + (rand()%31536000); dmap_set(dmap, i, val); } TIMER_SAMPLE(timer); fprintf(stdout, "set() 40000000 timestamps, time used:%lld\n", PT_LU_USEC(timer)); fflush(stdout); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { val = 1356969600 + (rand()%31536000); all += dmap_rangefrom(dmap, val, res); } TIMER_SAMPLE(timer); fprintf(stdout, "rangefrom() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer)); fflush(stdout); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { val = 1356969600 + (rand()%31536000); all += dmap_rangeto(dmap, val, res); } TIMER_SAMPLE(timer); fprintf(stdout, "rangeto() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer)); fflush(stdout); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { from = 1356969600 + (rand()%31536000); to = from + rand()%31536000; all += dmap_range(dmap, from, to, res); } TIMER_SAMPLE(timer); fprintf(stdout, "range(%p) 1000 times total:%lld, time used:%lld\n", res, (long long int)all, PT_LU_USEC(timer)); fflush(stdout); srand(time(NULL)); TIMER_RESET(timer); all = 0; for(i = 0; i < 1000; i++) { from = 1356969600 + (rand()%31536000); to = from + rand()%31536000; all += dmap_range(dmap, from, to, NULL); } TIMER_SAMPLE(timer); fprintf(stdout, "range(null) 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer)); fflush(stdout); #endif dmap_close(dmap); TIMER_CLEAN(timer); free(res); } }