Skip to content

Benchmark iteration test for binary 64 bit timer entries #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions rax-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,44 @@ int regtest6(void) {
}

void benchmark(void) {
printf("Benchmark with 64 bit binary timer keys incremented by random offsets:\n");
int random_offset;
char* data = "foobar";
uint16_t max_offset[] = {100, 200, 300, 500, 800, 1300, 2100, 3400, 5500, 8900, 14400};
int ro_len = sizeof(max_offset) / sizeof(max_offset[0]);

for (int j = 0; j < ro_len ; j++) {
rax* timers = raxNew();
uint64_t start = ustime();
uint64_t tm = start;
uint8_t tmv[8];

for (int i = 0; i < 5000000; i++) {
for (int k = 0; k < 8; k++) tmv[k] = tm >> ((7 - k) * 8) & 0xff;
raxInsert(timers, tmv, 8, data, NULL); /* big endian (network order) */
random_offset = max_offset[j] == 0 ? 0 : rc4rand() % max_offset[j];
tm = tm + random_offset + 1;
}

uint64_t interval_secs = (tm - start) / 1000000;
printf("Max random offset between timer entries: %d µsec\n", max_offset[j]);
printf("Total interval for timer entries: %f hours\n", (double)interval_secs / (60 * 60));
printf("Insert: %f secs\n", (double)(ustime() - start) / 1000000);
printf("%llu total nodes\n", (uint64_t)timers->numnodes);
printf("%llu total elements\n", (uint64_t)timers->numele);

start = ustime();
raxIterator ti;
raxStart(&ti, timers);
raxSeek(&ti, "^", NULL, 0);
int iter = 0;
while (raxNext(&ti)) iter++;
if (iter != 5000000) printf("** Warning iteration is incomplete\n");
printf("Full iteration: %f\n\n", (double)(ustime() - start) / 1000000);
raxStop(&ti);
raxFree(timers);
}

for (int mode = 0; mode < 2; mode++) {
printf("Benchmark with %s keys:\n",
(mode == 0) ? "integer" : "alphanumerical");
Expand Down