- prepareForBenchmark("PING");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"PING\r\n");
- prepareClientForReply(c,REPLY_RETCODE);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("PING (multi bulk)");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"*1\r\n$4\r\nPING\r\n");
- prepareClientForReply(c,REPLY_RETCODE);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("SET");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscatprintf(c->obuf,"SET foo_rand000000000000 %d\r\n",config.datasize);
- {
- char *data = zmalloc(config.datasize+2);
- memset(data,'x',config.datasize);
- data[config.datasize] = '\r';
- data[config.datasize+1] = '\n';
- c->obuf = sdscatlen(c->obuf,data,config.datasize+2);
- }
- prepareClientForReply(c,REPLY_RETCODE);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("GET");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"GET foo_rand000000000000\r\n");
- prepareClientForReply(c,REPLY_BULK);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("INCR");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"INCR counter_rand000000000000\r\n");
- prepareClientForReply(c,REPLY_INT);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("LPUSH");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n");
- prepareClientForReply(c,REPLY_INT);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("LPOP");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"LPOP mylist\r\n");
- prepareClientForReply(c,REPLY_BULK);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("SADD");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"SADD myset 24\r\ncounter_rand000000000000\r\n");
- prepareClientForReply(c,REPLY_RETCODE);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("SPOP");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"SPOP myset\r\n");
- prepareClientForReply(c,REPLY_BULK);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("LPUSH (again, in order to bench LRANGE)");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n");
- prepareClientForReply(c,REPLY_RETCODE);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("LRANGE (first 100 elements)");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"LRANGE mylist 0 99\r\n");
- prepareClientForReply(c,REPLY_MBULK);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("LRANGE (first 300 elements)");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"LRANGE mylist 0 299\r\n");
- prepareClientForReply(c,REPLY_MBULK);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("LRANGE (first 450 elements)");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"LRANGE mylist 0 449\r\n");
- prepareClientForReply(c,REPLY_MBULK);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
-
- prepareForBenchmark("LRANGE (first 600 elements)");
- c = createClient();
- if (!c) exit(1);
- c->obuf = sdscat(c->obuf,"LRANGE mylist 0 599\r\n");
- prepareClientForReply(c,REPLY_MBULK);
- createMissingClients(c);
- aeMain(config.el);
- endBenchmark();
+ char *data, *cmd;
+ int len;
+
+ data = zmalloc(config.datasize+1);
+ memset(data,'x',config.datasize);
+ data[config.datasize] = '\0';
+
+ benchmark("PING (inline)","PING\r\n",6);
+
+ len = redisFormatCommand(&cmd,"PING");
+ benchmark("PING",cmd,len);
+ free(cmd);
+
+ const char *argv[11];
+ argv[0] = "MSET";
+ for (i = 1; i < 11; i++)
+ argv[i] = data;
+ len = redisFormatCommandArgv(&cmd,11,argv,NULL);
+ benchmark("MSET (10 keys)",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"SET foo:rand:000000000000 %s",data);
+ benchmark("SET",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"GET foo:rand:000000000000");
+ benchmark("GET",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"INCR counter:rand:000000000000");
+ benchmark("INCR",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"LPUSH mylist %s",data);
+ benchmark("LPUSH",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"LPOP mylist");
+ benchmark("LPOP",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"SADD myset counter:rand:000000000000");
+ benchmark("SADD",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"SPOP myset");
+ benchmark("SPOP",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"LPUSH mylist %s",data);
+ benchmark("LPUSH (again, in order to bench LRANGE)",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"LRANGE mylist 0 99");
+ benchmark("LRANGE (first 100 elements)",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"LRANGE mylist 0 299");
+ benchmark("LRANGE (first 300 elements)",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"LRANGE mylist 0 449");
+ benchmark("LRANGE (first 450 elements)",cmd,len);
+ free(cmd);
+
+ len = redisFormatCommand(&cmd,"LRANGE mylist 0 599");
+ benchmark("LRANGE (first 600 elements)",cmd,len);
+ free(cmd);