summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-09-07 10:53:24 +0200
committerantirez <antirez@gmail.com>2016-09-07 10:53:47 +0200
commited6a4517f583c44da1559768e238d71a2a4667b9 (patch)
tree4ee8b52945ec1fc032e4f9aa33cbbb939fa88626
parent1074f73629daab5937218ebac264704385fca8a3 (diff)
downloadredis-ed6a4517f583c44da1559768e238d71a2a4667b9.tar.gz
dict.c benchmark improvements.
-rw-r--r--src/dict.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/dict.c b/src/dict.c
index cbd47527f..f1cafe2e2 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -1123,10 +1123,15 @@ dictType BenchmarkDictType = {
NULL
};
+#define start_benchmark() start = timeInMilliseconds()
+#define end_benchmark(msg) do { \
+ elapsed = timeInMilliseconds()-start; \
+ printf(msg ": %ld items in %lld ms\n", count, elapsed); \
+} while(0);
+
/* dict-benchmark [count] */
int main(int argc, char **argv) {
long j;
- long hits = 0, misses = 0;
long long start, elapsed;
dict *dict = dictCreate(&BenchmarkDictType,NULL);
long count = 0;
@@ -1137,13 +1142,31 @@ int main(int argc, char **argv) {
count = 5000000;
}
- start = timeInMilliseconds();
+ start_benchmark();
for (j = 0; j < count; j++) {
int retval = dictAdd(dict,sdsfromlonglong(j),(void*)j);
assert(retval == DICT_OK);
}
- elapsed = timeInMilliseconds()-start;
- printf("Inserting 5M items: %lld ms\n", elapsed);
+ end_benchmark("Inserting");
assert((long)dictSize(dict) == count);
+
+ start_benchmark();
+ for (j = 0; j < count; j++) {
+ sds key = sdsfromlonglong(rand() % count);
+ dictEntry *de = dictFind(dict,key);
+ assert(de != NULL);
+ sdsfree(key);
+ }
+ end_benchmark("Accessing existing");
+
+ start_benchmark();
+ for (j = 0; j < count; j++) {
+ sds key = sdsfromlonglong(rand() % count);
+ key[0] = 'X';
+ dictEntry *de = dictFind(dict,key);
+ assert(de == NULL);
+ sdsfree(key);
+ }
+ end_benchmark("Accessing missing");
}
#endif