Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Created September 18, 2008 02:28
Show Gist options
  • Save tokuhirom/11360 to your computer and use it in GitHub Desktop.
Save tokuhirom/11360 to your computer and use it in GitHub Desktop.
#include <libmemcached/memcached.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define KEY "counter"
#define KEYLEN 7
int main (int argc, char **argv) {
uint64_t buf;
int i;
int num = atoi(argv[1]);
size_t value_length;
uint32_t flags;
memcached_return rc;
char * res;
int binary;
for (binary=0; binary<=1; binary++) {
memcached_st *memc = memcached_create(NULL);;
memcached_server_add(memc, "127.0.0.1", 11212);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, binary);
memcached_set(memc, KEY, KEYLEN, "0", 1, 0, 0);
clock_t t1 = clock();
for (i=0; i<num; i++) {
memcached_increment(memc, KEY, KEYLEN, 1, &buf);
}
clock_t t2 = clock();
res = memcached_get(memc, KEY, KEYLEN, &value_length, &flags, &rc);
printf("Result: %d, Time: %10.3f, Binary: %d\n", atoi(res), (double)(t2-t1), binary);
memcached_free(memc);
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment