add hash/kvs-client
This commit is contained in:
121
testcase.c
121
testcase.c
@@ -90,9 +90,9 @@ void array_testcase(int connfd) {
|
||||
|
||||
}
|
||||
|
||||
void array_testcase_10w(int connfd) {
|
||||
void array_testcase_1w(int connfd) {
|
||||
|
||||
int count = 1000;
|
||||
int count = 10000;
|
||||
int i = 0;
|
||||
|
||||
struct timeval tv_begin;
|
||||
@@ -117,7 +117,7 @@ void array_testcase_10w(int connfd) {
|
||||
|
||||
int time_used = TIME_SUB_MS(tv_end, tv_begin); // ms
|
||||
|
||||
printf("array testcase --> time_used: %d, qps: %d\n", time_used, 9000 * 1000 / time_used);
|
||||
printf("array testcase --> time_used: %d, qps: %d\n", time_used, 90000 * 1000 / time_used);
|
||||
|
||||
}
|
||||
|
||||
@@ -125,34 +125,129 @@ void array_testcase_10w(int connfd) {
|
||||
void rbtree_testcase(int connfd) {
|
||||
|
||||
testcase(connfd, "RSET Teacher King", "OK\r\n", "RSET-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "King\r\n", "RGET-Teacher");
|
||||
testcase(connfd, "RMOD Teacher Darren", "OK\r\n", "RMOD-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "Darren\r\n", "RGET-Teacher");
|
||||
testcase(connfd, "REXIST Teacher", "EXIST\r\n", "RGET-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "King\r\n", "RGET-King-Teacher");
|
||||
testcase(connfd, "RMOD Teacher Darren", "OK\r\n", "RMOD-D-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "Darren\r\n", "RGET-Darren-Teacher");
|
||||
testcase(connfd, "REXIST Teacher", "EXIST\r\n", "REXIST-Teacher");
|
||||
testcase(connfd, "RDEL Teacher", "OK\r\n", "RDEL-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "NO EXIST\r\n", "RGET-Teacher");
|
||||
testcase(connfd, "RMOD Teacher KING", "NO EXIST\r\n", "RMOD-Teacher");
|
||||
testcase(connfd, "REXIST Teacher", "NO EXIST\r\n", "RGET-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "NO EXIST\r\n", "RGET-K-Teacher");
|
||||
testcase(connfd, "RMOD Teacher KING", "NO EXIST\r\n", "RMOD-K-Teacher");
|
||||
testcase(connfd, "REXIST Teacher", "NO EXIST\r\n", "REXIST-Teacher");
|
||||
|
||||
}
|
||||
|
||||
void rbtree_testcase_1w(int connfd) {
|
||||
|
||||
int count = 10000;
|
||||
int i = 0;
|
||||
|
||||
struct timeval tv_begin;
|
||||
gettimeofday(&tv_begin, NULL);
|
||||
|
||||
for (i = 0;i < count;i ++) {
|
||||
|
||||
testcase(connfd, "RSET Teacher King", "OK\r\n", "RSET-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "King\r\n", "RGET-King-Teacher");
|
||||
testcase(connfd, "RMOD Teacher Darren", "OK\r\n", "RMOD-D-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "Darren\r\n", "RGET-Darren-Teacher");
|
||||
testcase(connfd, "REXIST Teacher", "EXIST\r\n", "REXIST-Teacher");
|
||||
testcase(connfd, "RDEL Teacher", "OK\r\n", "RDEL-Teacher");
|
||||
testcase(connfd, "RGET Teacher", "NO EXIST\r\n", "RGET-K-Teacher");
|
||||
testcase(connfd, "RMOD Teacher KING", "NO EXIST\r\n", "RMOD-K-Teacher");
|
||||
testcase(connfd, "REXIST Teacher", "NO EXIST\r\n", "REXIST-Teacher");
|
||||
|
||||
}
|
||||
|
||||
struct timeval tv_end;
|
||||
gettimeofday(&tv_end, NULL);
|
||||
|
||||
int time_used = TIME_SUB_MS(tv_end, tv_begin); // ms
|
||||
|
||||
printf("rbtree testcase --> time_used: %d, qps: %d\n", time_used, 90000 * 1000 / time_used);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void rbtree_testcase_3w(int connfd) {
|
||||
|
||||
int count = 10000;
|
||||
int i = 0;
|
||||
|
||||
struct timeval tv_begin;
|
||||
gettimeofday(&tv_begin, NULL);
|
||||
|
||||
for (i = 0;i < count;i ++) {
|
||||
|
||||
char cmd[128] = {0};
|
||||
snprintf(cmd, 128, "RSET Teacher%d King%d", i, i);
|
||||
testcase(connfd, cmd, "OK\r\n", "RSET-Teacher");
|
||||
}
|
||||
|
||||
for (i = 0;i < count;i ++) {
|
||||
|
||||
char cmd[128] = {0};
|
||||
snprintf(cmd, 128, "RGET Teacher%d", i);
|
||||
|
||||
char result[128] = {0};
|
||||
snprintf(result, 128, "King%d\r\n", i);
|
||||
|
||||
testcase(connfd, cmd, result, "RGET-King-Teacher");
|
||||
}
|
||||
|
||||
for (i = 0;i < count;i ++) {
|
||||
|
||||
char cmd[128] = {0};
|
||||
snprintf(cmd, 128, "RMOD Teacher%d King%d", i, i);
|
||||
testcase(connfd, cmd, "OK\r\n", "RGET-King-Teacher");
|
||||
}
|
||||
|
||||
struct timeval tv_end;
|
||||
gettimeofday(&tv_end, NULL);
|
||||
|
||||
int time_used = TIME_SUB_MS(tv_end, tv_begin); // ms
|
||||
|
||||
printf("rbtree testcase --> time_used: %d, qps: %d\n", time_used, 30000 * 1000 / time_used);
|
||||
|
||||
}
|
||||
|
||||
void hash_testcase(int connfd) {
|
||||
|
||||
testcase(connfd, "HSET Teacher King", "OK\r\n", "HSET-Teacher");
|
||||
testcase(connfd, "HGET Teacher", "King\r\n", "HGET-King-Teacher");
|
||||
testcase(connfd, "HMOD Teacher Darren", "OK\r\n", "HMOD-D-Teacher");
|
||||
testcase(connfd, "HGET Teacher", "Darren\r\n", "HGET-Darren-Teacher");
|
||||
testcase(connfd, "HEXIST Teacher", "EXIST\r\n", "HEXIST-Teacher");
|
||||
testcase(connfd, "HDEL Teacher", "OK\r\n", "HDEL-Teacher");
|
||||
testcase(connfd, "HGET Teacher", "NO EXIST\r\n", "HGET-K-Teacher");
|
||||
testcase(connfd, "HMOD Teacher KING", "NO EXIST\r\n", "HMOD-K-Teacher");
|
||||
testcase(connfd, "HEXIST Teacher", "NO EXIST\r\n", "HEXIST-Teacher");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// testcase 192.168.243.131 2000
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc != 3) {
|
||||
if (argc != 4) {
|
||||
printf("arg error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *ip = argv[1];
|
||||
int port = atoi(argv[2]);
|
||||
int mode = atoi(argv[3]);
|
||||
|
||||
int connfd = connect_tcpserver(ip, port);
|
||||
|
||||
rbtree_testcase(connfd);
|
||||
//array_testcase_10w(connfd);
|
||||
if (mode == 0) {
|
||||
rbtree_testcase_1w(connfd);
|
||||
} else if (mode == 1) {
|
||||
rbtree_testcase_3w(connfd);
|
||||
} else if (mode == 2) {
|
||||
array_testcase_1w(connfd);
|
||||
} else if (mode == 3) {
|
||||
hash_testcase(connfd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user