MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / test_throughput

Function test_throughput

deps/hiredis/test.c:1098–1185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1096}
1097
1098static void test_throughput(struct config config) {
1099 redisContext *c = do_connect(config);
1100 redisReply **replies;
1101 int i, num;
1102 long long t1, t2;
1103
1104 test("Throughput:\n");
1105 for (i = 0; i < 500; i++)
1106 freeReplyObject(redisCommand(c,"LPUSH mylist foo"));
1107
1108 num = 1000;
1109 replies = hi_malloc_safe(sizeof(redisReply*)*num);
1110 t1 = usec();
1111 for (i = 0; i < num; i++) {
1112 replies[i] = redisCommand(c,"PING");
1113 assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS);
1114 }
1115 t2 = usec();
1116 for (i = 0; i < num; i++) freeReplyObject(replies[i]);
1117 hi_free(replies);
1118 printf("\t(%dx PING: %.3fs)\n", num, (t2-t1)/1000000.0);
1119
1120 replies = hi_malloc_safe(sizeof(redisReply*)*num);
1121 t1 = usec();
1122 for (i = 0; i < num; i++) {
1123 replies[i] = redisCommand(c,"LRANGE mylist 0 499");
1124 assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_ARRAY);
1125 assert(replies[i] != NULL && replies[i]->elements == 500);
1126 }
1127 t2 = usec();
1128 for (i = 0; i < num; i++) freeReplyObject(replies[i]);
1129 hi_free(replies);
1130 printf("\t(%dx LRANGE with 500 elements: %.3fs)\n", num, (t2-t1)/1000000.0);
1131
1132 replies = hi_malloc_safe(sizeof(redisReply*)*num);
1133 t1 = usec();
1134 for (i = 0; i < num; i++) {
1135 replies[i] = redisCommand(c, "INCRBY incrkey %d", 1000000);
1136 assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_INTEGER);
1137 }
1138 t2 = usec();
1139 for (i = 0; i < num; i++) freeReplyObject(replies[i]);
1140 hi_free(replies);
1141 printf("\t(%dx INCRBY: %.3fs)\n", num, (t2-t1)/1000000.0);
1142
1143 num = 10000;
1144 replies = hi_malloc_safe(sizeof(redisReply*)*num);
1145 for (i = 0; i < num; i++)
1146 redisAppendCommand(c,"PING");
1147 t1 = usec();
1148 for (i = 0; i < num; i++) {
1149 assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK);
1150 assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS);
1151 }
1152 t2 = usec();
1153 for (i = 0; i < num; i++) freeReplyObject(replies[i]);
1154 hi_free(replies);
1155 printf("\t(%dx PING (pipelined): %.3fs)\n", num, (t2-t1)/1000000.0);

Callers 1

mainFunction · 0.85

Calls 9

do_connectFunction · 0.85
freeReplyObjectFunction · 0.85
hi_malloc_safeFunction · 0.85
redisAppendCommandFunction · 0.85
redisGetReplyFunction · 0.85
disconnectFunction · 0.85
redisCommandFunction · 0.70
usecFunction · 0.70
hi_freeFunction · 0.70

Tested by

no test coverage detected