/*
* 1. build netdata (as normally)
* 2. cd profile/
* 3. compile with:
* gcc -O3 -Wall -Wextra -I ../src/ -I ../ -o benchmark-dictionary benchmark-dictionary.c ../src/dictionary.o ../src/log.o ../src/avl.o ../src/common.o -pthread
*
*/
#include "common.h"
struct myvalue {
int i;
};
void netdata_cleanup_and_exit(int ret) { exit(ret); }
int main(int argc, char **argv) {
if(argc || argv) {;}
// DICTIONARY *dict = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED|DICTIONARY_FLAG_WITH_STATISTICS);
DICTIONARY *dict = dictionary_create(DICTIONARY_FLAG_WITH_STATISTICS);
if(!dict) fatal("Cannot create dictionary.");
struct rusage start, end;
unsigned long long dt;
char buf[100 + 1];
struct myvalue value, *v;
int i, max = 30000000, max2;
// ------------------------------------------------------------------------
getrusage(RUSAGE_SELF, &start);
dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
fprintf(stderr, "Inserting %d entries in the dictionary\n", max);
for(i = 0; i < max; i++) {
value.i = i;
snprintf(buf, 100, "%d", i);
dictionary_set(dict, buf, &value, sizeof(struct myvalue));
}
getrusage(RUSAGE_SELF, &end);
dt = (end.ru_utime.tv_sec * 1000000ULL + end.ru_utime.tv_usec) - (start.ru_utime.tv_sec * 1000000ULL + start.ru_utime.tv_usec);
fprintf(stderr, "Added %d entries in %llu nanoseconds: %llu inserts per second\n", max, dt, max * 1000000ULL / dt);
fprintf(stderr, " > Dictionary: %llu inserts, %llu deletes, %llu searches\n\n", dict->stats->inserts, dict->stats->deletes, dict->stats->searches);
// ------------------------------------------------------------------------
getrusage(RUSAGE_SELF, &start);
dict->stats->inserts = dict->stats->deletes = dict->stats->searches = 0ULL;
fprintf(stderr, "Retrieving %d entries from the dictionary\n", max);
for21.0.0-beta1