From 752f34227717d416f3f36bcdae50324f084e8b6b Mon Sep 17 00:00:00 2001 From: Tylo Date: Thu, 18 Jun 2020 12:04:55 +0200 Subject: Some fixes of benchmark, and some code improvements. --- benchmark.c | 15 ++++++++------- stc/copt.h | 2 +- stc/crandom.h | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/benchmark.c b/benchmark.c index 8672e1ca..8b6a49c8 100644 --- a/benchmark.c +++ b/benchmark.c @@ -25,11 +25,12 @@ KHASH_MAP_INIT_INT64(ii, uint64_t) size_t seed = 1234; static const double maxLoadFactor = 0.77; + sfc64_t rng; #define SEED(s) rng = sfc64_seed(seed) #define RAND(N) (sfc64_rand(&rng) & ((1 << N) - 1)) - -//#define SEED(s) mt19937_t rng = mt19937_seed(s) +//mt19937_t rng; +//#define SEED(s) rng = mt19937_seed(s) //#define RAND(N) (mt19937_rand(&rng) & ((1 << N) - 1)) @@ -92,7 +93,6 @@ int rr = RR; { \ M##_SETUP(tag, int64_t, int64_t); \ uint64_t checksum = 0, erased = 0; \ - seed = time(NULL); \ SEED(seed); \ clock_t difference, before = clock(); \ for (size_t i = 0; i < N1; ++i) { \ @@ -124,7 +124,6 @@ int rr = RR; { \ M##_SETUP(tag, int64_t, int64_t); \ size_t erased = 0; \ - seed = time(NULL); \ clock_t difference, before = clock(); \ SEED(seed); \ for (size_t i = 0; i < N2; ++i) \ @@ -142,7 +141,9 @@ int rr = RR; int main(int argc, char* argv[]) { rr = argc == 2 ? atoi(argv[1]) : RR; - printf("\nmap: Insert + remove %zu random keys in range 0 - 2^%d:\n", N1, rr); + seed = time(NULL); + printf("\nRandom keys are in range [0, 2^%d):\n", rr); + printf("\nmap: %zu repeats of Insert random key + remove a different random key:\n", N1); MAP_TEST1(CMAP, ii) MAP_TEST1(KMAP, ii) #ifdef __cplusplus @@ -152,7 +153,7 @@ int main(int argc, char* argv[]) MAP_TEST1(RMAP, ii) #endif - printf("\nmap: Insert %zu linear keys, THEN remove them in same order:\n", N2); + printf("\nmap: Insert %zu index keys, then remove them in same order:\n", N2); MAP_TEST2(CMAP, ii) MAP_TEST2(KMAP, ii) #ifdef __cplusplus @@ -162,7 +163,7 @@ int main(int argc, char* argv[]) MAP_TEST2(RMAP, ii) #endif - printf("\nmap: Insert %zu random keys, THEN remove them in same order:\n", N2); + printf("\nmap: Insert %zu random keys, then remove them in same order:\n", N2); MAP_TEST3(CMAP, ii) MAP_TEST3(KMAP, ii) #ifdef __cplusplus diff --git a/stc/copt.h b/stc/copt.h index 65b32608..4c6af63d 100644 --- a/stc/copt.h +++ b/stc/copt.h @@ -83,7 +83,7 @@ struct copt_option { int val; }; -static const copt_t copt_init = {1, 0, NULL, NULL, -1, 1, 0, 0, {'-', 0, 0, 0}}; +static const copt_t copt_init = {1, 0, NULL, NULL, -1, 1, 0, 0, {'-', '?', '\0'}}; static void _copt_permute(char *argv[], int j, int n) { /* move argv[j] over n elements to the left */ int k; diff --git a/stc/crandom.h b/stc/crandom.h index 40b11cfb..167993e2 100644 --- a/stc/crandom.h +++ b/stc/crandom.h @@ -236,7 +236,7 @@ STC_API siphash_t siphash_init(const uint64_t key[2]) { } #define _siphash_digest(rounds, v, m) { \ - uint64_t _m = m; \ + const uint64_t _m = m; \ v[3] ^= _m; \ _siphash_compress(rounds, v); \ v[0] ^= _m; \ @@ -250,7 +250,7 @@ STC_API void siphash_update(siphash_t* s, const void* bytes, size_t size) { s->length += size; if (offset) { - size_t end = offset + size; + const size_t end = offset + size; size -= 8 - offset; while (offset < end && offset < 8) { s->padding |= ((uint64_t) *in.u8++) << (offset++ << 3); -- cgit v1.2.3