mirror of
https://github.com/fluencelabs/redis
synced 2025-03-29 05:41:03 +00:00
dict.c benchmark improvements.
This commit is contained in:
parent
1074f73629
commit
ed6a4517f5
31
src/dict.c
31
src/dict.c
@ -1123,10 +1123,15 @@ dictType BenchmarkDictType = {
|
|||||||
NULL
|
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] */
|
/* dict-benchmark [count] */
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
long j;
|
long j;
|
||||||
long hits = 0, misses = 0;
|
|
||||||
long long start, elapsed;
|
long long start, elapsed;
|
||||||
dict *dict = dictCreate(&BenchmarkDictType,NULL);
|
dict *dict = dictCreate(&BenchmarkDictType,NULL);
|
||||||
long count = 0;
|
long count = 0;
|
||||||
@ -1137,13 +1142,31 @@ int main(int argc, char **argv) {
|
|||||||
count = 5000000;
|
count = 5000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = timeInMilliseconds();
|
start_benchmark();
|
||||||
for (j = 0; j < count; j++) {
|
for (j = 0; j < count; j++) {
|
||||||
int retval = dictAdd(dict,sdsfromlonglong(j),(void*)j);
|
int retval = dictAdd(dict,sdsfromlonglong(j),(void*)j);
|
||||||
assert(retval == DICT_OK);
|
assert(retval == DICT_OK);
|
||||||
}
|
}
|
||||||
elapsed = timeInMilliseconds()-start;
|
end_benchmark("Inserting");
|
||||||
printf("Inserting 5M items: %lld ms\n", elapsed);
|
|
||||||
assert((long)dictSize(dict) == count);
|
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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user