diff options
| -rw-r--r-- | benchmarks/shootout_hashmaps.cpp | 22 | ||||
| -rwxr-xr-x | examples/make.sh | 3 | ||||
| -rw-r--r-- | include/stc/csview.h | 4 | ||||
| -rw-r--r-- | src/cregex.c | 14 |
4 files changed, 20 insertions, 23 deletions
diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp index 4e79ff6e..78d7bce2 100644 --- a/benchmarks/shootout_hashmaps.cpp +++ b/benchmarks/shootout_hashmaps.cpp @@ -1,9 +1,6 @@ #include <stdio.h> #include <time.h> -#define i_static #include <stc/crandom.h> -#include <stc/cstr.h> -#include "external/khash.h" #define MAX_LOAD_FACTOR 77 @@ -32,6 +29,7 @@ typedef int64_t IKey; typedef int64_t IValue; // khash template expansion +#include "external/khash.h" KHASH_MAP_INIT_INT64(ii, IValue) // cmap template expansion @@ -223,14 +221,14 @@ KHASH_MAP_INIT_INT64(ii, IValue) #define MAP_TEST3(M, X, n) \ { /* Erase elements */ \ M##_SETUP(X, IKey, IValue); \ - size_t erased = 0; \ + size_t erased = 0, _n = (n)*2; \ clock_t difference, before; \ SEED(seed); \ - for (size_t i = 0; i < n; ++i) \ + for (size_t i = 0; i < _n; ++i) \ M##_EMPLACE(X, RAND(keybits), i); \ SEED(seed); \ before = clock(); \ - for (size_t i = 0; i < n; ++i) \ + for (size_t i = 0; i < _n; ++i) \ erased += M##_ERASE(X, RAND(keybits)); \ difference = clock() - before; \ printf(#M ": %5.03f s, size: %" c_ZU ", buckets: %8" c_ZU ", erased %" c_ZU "\n", \ @@ -246,7 +244,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) SEED(seed); \ for (size_t i = 0; i < m; ++i) \ M##_EMPLACE(X, RAND(keybits), i); \ - size_t rep = 30000000ull/M##_SIZE(X); \ + size_t rep = 60000000ull/M##_SIZE(X); \ clock_t difference, before = clock(); \ for (size_t k=0; k < rep; k++) M##_FOR (X, it) \ sum += M##_ITEM(X, it); \ @@ -267,7 +265,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) M##_EMPLACE(X, RAND(keybits), i); \ before = clock(); \ /* Lookup x random keys */ \ - size_t x = m * 3000000ull/M##_SIZE(X); \ + size_t x = m * 8000000ull/M##_SIZE(X); \ for (size_t i = 0; i < x; ++i) \ found += M##_FIND(X, RAND(keybits)); \ /* Lookup x existing keys by resetting seed */ \ @@ -315,7 +313,7 @@ int main(int argc, char* argv[]) unsigned n_mill = argc >= 2 ? atoi(argv[1]) : DEFAULT_N_MILL; unsigned keybits = argc >= 3 ? atoi(argv[2]) : DEFAULT_KEYBITS; unsigned n = n_mill * 1000000; - unsigned N1 = n, N2 = n, N3 = n*2, N4 = n*2, N5 = n*2; + unsigned N1 = n, N2 = n, N3 = n, N4 = n, N5 = n; stc64_t rng; size_t seed = time(NULL); @@ -340,12 +338,12 @@ int main(int argc, char* argv[]) printf("\nT2: Insert %g mill. SEQUENTIAL keys, erase them in same order:\n", N2/1000000.0); RUN_TEST(2) - printf("\nT3: Erase all elements (%u mill. random inserts), key range [0, 2^%u)\n", n_mill*2, keybits); + printf("\nT3: Erase all elements by lookup (%u mill. random inserts), key range [0, 2^%u)\n", n_mill*2, keybits); RUN_TEST(3) - printf("\nT4: Iterate map repeated times:\n"); + printf("\nT4: Iterate map with Min(%u mill, 2^%u) inserts repeated times:\n", n_mill, keybits+1); RUN_TEST(4) - printf("\nT5: Lookup half-half random/existing keys in range [0, 2^%u). Num lookups depends on size.\n", keybits); + printf("\nT5: Lookup mix of random/existing keys in range [0, 2^%u). Num lookups depends on size.\n", keybits); RUN_TEST(5) } diff --git a/examples/make.sh b/examples/make.sh index a25c517a..7dc07613 100755 --- a/examples/make.sh +++ b/examples/make.sh @@ -6,7 +6,8 @@ if [ "$(uname)" = 'Linux' ]; then oflag='-o ' fi -cc=gcc; cflags="-s -O2 -Wall -std=c99 -pedantic -Wfatal-errors $sanitize" +#cc=gcc; cflags="-s -O2 -Wall -std=c99 -pedantic -Wfatal-errors $sanitize" +cc=gcc; cflags="-s -O2 -Werror -Wfatal-errors -Wall -Wpedantic -Wsign-compare -Wwrite-strings" # -Wconversion #cc=tcc; cflags="-Wall -std=c99" #cc=clang; cflags="-s -O2 -Wall -std=c99 -pedantic -Wfatal-errors" #cc=clang; cflags="-s -O2 -Wall -std=c99 -pedantic -Wfatal-errors -DSTC_CSTR_V1 -DSTC_CSMAP_V1" diff --git a/include/stc/csview.h b/include/stc/csview.h index b94e93b4..cccf21ea 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -164,7 +164,7 @@ STC_API uint64_t csview_hash(const csview *self); STC_DEF size_t csview_find_sv(csview sv, csview search) { char* res = cstrnstrn(sv.str, search.str, sv.size, search.size); - return res ? res - sv.str : csview_npos; + return res ? (size_t)(res - sv.str) : csview_npos; } STC_DEF uint64_t csview_hash(const csview *self) @@ -196,7 +196,7 @@ STC_DEF csview csview_token(csview sv, const char* sep, size_t* start) { size_t sep_size = strlen(sep); csview slice = {sv.str + *start, sv.size - *start}; const char* res = cstrnstrn(slice.str, sep, slice.size, sep_size); - csview tok = {slice.str, res ? res - slice.str : slice.size}; + csview tok = {slice.str, res ? (size_t)(res - slice.str) : slice.size}; *start += tok.size + sep_size; return tok; } diff --git a/src/cregex.c b/src/cregex.c index 6eadd257..413e1620 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -79,7 +79,7 @@ typedef struct _Reprog { _Reinst *startinst; /* start pc */ _Reflags flags; - int nsubids; + unsigned nsubids; _Reclass cclass[_NCLASS]; /* .data */ _Reinst firstinst[]; /* .text : originally 5 elements? */ } _Reprog; @@ -224,15 +224,13 @@ utfruneicase(const char *s, _Rune c) * save a new match in mp */ static void -_renewmatch(_Resub *mp, unsigned ms, _Resublist *sp, int nsubids) +_renewmatch(_Resub *mp, unsigned ms, _Resublist *sp, unsigned nsubids) { - int i; - if (mp==NULL || ms==0) return; if (mp[0].str == NULL || sp->m[0].str < mp[0].str || (sp->m[0].str == mp[0].str && sp->m[0].size > mp[0].size)) { - for (i=0; i<ms && i<=nsubids; i++) + for (unsigned i=0; i<ms && i<=nsubids; i++) mp[i] = sp->m[i]; } } @@ -937,9 +935,9 @@ _regexec1(const _Reprog *progp, /* program to run */ _Relist *tl, *nl; /* This list, next list */ _Relist *tle, *nle; /* Ends of this and next list */ const char *s, *p; - int i, n, checkstart; _Rune r, *rp, *ep; - int match = 0; + int n, checkstart, match = 0; + unsigned i; bool icase = progp->flags.caseless; checkstart = j->starttype; @@ -1157,7 +1155,7 @@ _build_subst(const char* replace, unsigned nmatch, const csview match[], while (*replace != '\0') { if (*replace == '$') { const int arg = *++replace; - int g; + unsigned g; switch (arg) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': |
