From 10c6a1e8a65aaac7c31351163bcd9d6c362e10e1 Mon Sep 17 00:00:00 2001 From: Tyge Date: Wed, 29 Apr 2020 16:35:20 +0200 Subject: Some small tweaks. Simplified hash32 function, makes it faster even if distribution is worse (good enough). --- benchmark.c | 22 ++++++++-------------- stc/cdefs.h | 6 +++--- stc/cvector.h | 7 ++++++- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/benchmark.c b/benchmark.c index 9bf3722d..2e5d2b34 100644 --- a/benchmark.c +++ b/benchmark.c @@ -13,8 +13,7 @@ // Visual Studio: compile with -TP to force C++: cl -TP -EHsc -O2 benchmark.c declare_CMap(ii, int64_t, int64_t, c_noDestroy, c_lowbias32Hash); -declare_CVector_string(s); -declare_CMap(ix, short, short); // sizeof(CMapBucket_ix) = 6 bytes only! +declare_CMap(ix, short, short); // sizeof(CMapEntry_ix) = 6 bytes only! const size_t seed = 123; // time(NULL); const double maxLoadFactor = 0.77; @@ -64,6 +63,7 @@ const double maxLoadFactor = 0.77; const size_t N1 = 7000000; const size_t N2 = 10000000; #define RR 24 +int rr = RR; #define MAP_TEST1(M, tag) \ { \ @@ -72,8 +72,8 @@ const size_t N2 = 10000000; srand(seed); \ clock_t difference, before = clock(); \ for (size_t i = 0; i < N1; ++i) { \ - checksum += ++M##_PUT(tag, RAND(RR), i); \ - erased += M##_DEL(tag, RAND(RR)); \ + checksum += ++M##_PUT(tag, RAND(rr), i); \ + erased += M##_DEL(tag, RAND(rr)); \ } \ difference = clock() - before; \ printf(#M "(" #tag "): sz: %llu, bucks: %llu, time: %.02f, sum: %llu, erase: %llu\n", M##_SIZE(tag), M##_BUCKETS(tag), (float) difference / CLOCKS_PER_SEC, checksum, erased); \ @@ -96,9 +96,10 @@ const size_t N2 = 10000000; } -int main() +int main(int argc, char* argv[]) { - printf("\nmap: Insert + remove %llu random keys in range 0 - 2^%d:\n", N1, RR); \ + rr = argc == 2 ? atoi(argv[1]) : RR; + printf("\nmap: Insert + remove %llu random keys in range 0 - 2^%d:\n", N1, rr); MAP_TEST1(CMAP, ii) #ifdef __cplusplus MAP_TEST1(UMAP, ii) @@ -107,7 +108,7 @@ int main() MAP_TEST1(RMAP, ii) #endif - printf("\nmap: Insert %llu keys, THEN remove them in same order:\n", N2); \ + printf("\nmap: Insert %llu keys, THEN remove them in same order:\n", N2); MAP_TEST2(CMAP, ii) #ifdef __cplusplus MAP_TEST2(UMAP, ii) @@ -116,11 +117,4 @@ int main() MAP_TEST2(RMAP, ii) #endif - CMap_ix small = cmap_init; - cmap_ix_put(&small, 80, 800); - cmap_ix_put(&small, 10, 100); - cmap_ix_put(&small, 30, 300); - - c_foreach (i, cmap_ix, small) - printf("%d: %d\n", i.item->key, i.item->value); } diff --git a/stc/cdefs.h b/stc/cdefs.h index c1635fa5..1c75abcc 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -81,9 +81,9 @@ static inline uint32_t c_lowbias32Hash(const void *data, size_t len) { do { x ^= *key++ >> 16; x *= UINT32_C(0x7feb352d); - x ^= x >> 15; - x *= UINT32_C(0x846ca68b); - x ^= x >> 16; + //x ^= x >> 15; + //x *= UINT32_C(0x846ca68b); + //x ^= x >> 16; } while (len -= 4); return x; } diff --git a/stc/cvector.h b/stc/cvector.h index 0e64fd86..86bdfb13 100644 --- a/stc/cvector.h +++ b/stc/cvector.h @@ -184,7 +184,7 @@ cvector_##tag##_sortCompare(const void* x, const void* y) { \ ValueRaw ry = valueGetRaw((const Value *) y); \ return valueCompareRaw(&rx, &ry); \ } \ -extern void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)); \ +STC_EXTERN_IMPORT void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)); \ STC_API void \ cvector_##tag##_sort(CVector_##tag* self) { \ size_t len = cvector_size(*self); \ @@ -202,6 +202,11 @@ cvector_##tag##_begin(CVector_##tag* vec) { \ #define implement_CVector_6(tag, Value, valueDestroy, ValueRaw, valueCompareRaw, valueGetRaw) #endif +#if defined(_WIN32) && defined(_DLL) +#define STC_EXTERN_IMPORT extern __declspec(dllimport) +#else +#define STC_EXTERN_IMPORT extern +#endif #define _cvector_size(cv) ((size_t *)(cv).data)[-2] #define _cvector_capacity(cv) ((size_t *)(cv).data)[-1] -- cgit v1.2.3