aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-03-21 19:53:23 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-21 19:53:47 -0600
commitd74a43f4ad4470a7a2f056020c330576067de2b0 (patch)
tree8b6174f8131c35e0852b97d4a3aa4e55c0ee803f
parentAdd linear probe example too (diff)
downloadpubkey-hash-table-d74a43f4ad4470a7a2f056020c330576067de2b0.tar.xz
pubkey-hash-table-d74a43f4ad4470a7a2f056020c330576067de2b0.zip
Benchmark themHEADmaster
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--hashtable.c6
-rw-r--r--linearprobe.c6
2 files changed, 12 insertions, 0 deletions
diff --git a/hashtable.c b/hashtable.c
index d088bfa..3702c36 100644
--- a/hashtable.c
+++ b/hashtable.c
@@ -1,9 +1,11 @@
/* Copyright (C) 2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */
+#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <time.h>
#include <sys/random.h>
struct entry {
@@ -116,6 +118,7 @@ static struct entry *find_or_insert_entry(uint8_t key[32])
/* Just a small test */
int main(int argc, char *argv[])
{
+ struct timespec start, end;
uint8_t key[32] = { 0 };
int i;
@@ -127,6 +130,7 @@ int main(int argc, char *argv[])
entry->some_member = i ^ 0xffffffff;
}
+ clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < 1 << 20; ++i) {
struct entry *entry;
@@ -135,6 +139,8 @@ int main(int argc, char *argv[])
assert(entry);
assert(entry->some_member == i ^ 0xffffffff);
}
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ printf("%s: %llu ns\n", argv[0], (end.tv_sec * 1000000000ULL + end.tv_nsec) - (start.tv_sec * 1000000000ULL + start.tv_nsec));
return 0;
}
diff --git a/linearprobe.c b/linearprobe.c
index 5760ee3..06d93d2 100644
--- a/linearprobe.c
+++ b/linearprobe.c
@@ -1,9 +1,11 @@
/* Copyright (C) 2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */
+#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <time.h>
#include <sys/random.h>
struct entry {
@@ -125,6 +127,7 @@ static struct entry *find_or_insert_entry(uint8_t key[32])
/* Just a small test */
int main(int argc, char *argv[])
{
+ struct timespec start, end;
uint8_t key[32] = { 0 };
int i;
@@ -136,6 +139,7 @@ int main(int argc, char *argv[])
entry->some_member = i ^ 0xffffffff;
}
+ clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < 1 << 20; ++i) {
struct entry *entry;
@@ -144,6 +148,8 @@ int main(int argc, char *argv[])
assert(entry);
assert(entry->some_member == i ^ 0xffffffff);
}
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ printf("%s: %llu ns\n", argv[0], (end.tv_sec * 1000000000ULL + end.tv_nsec) - (start.tv_sec * 1000000000ULL + start.tv_nsec));
return 0;
}