From 12d7c1b3ca437af8734acc8e7cbfdba08b8c36df Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 15 Dec 2020 22:14:10 +0100 Subject: Minors on crandom and example. --- examples/random.c | 42 +++++++++++++++++++++++++----------------- stc/crandom.h | 8 -------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/random.c b/examples/random.c index 4834a974..0cf9da6f 100644 --- a/examples/random.c +++ b/examples/random.c @@ -1,43 +1,51 @@ #include #include +#include #include #include int main() { enum {R = 30}; - const size_t N = 100000000; - clock_t diff, before; - uint64_t sum = 0; + const size_t N = 500000000; uint64_t seed = time(NULL); - cstc64_t stc = cstc64_init(seed); - cstc64_uniform_t dist1 = cstc64_uniform_init(0, N); - sum = 0; - before = clock(); - c_forrange (N) { - sum += cstc64_uniform(&stc, &dist1); - } - diff = clock() - before; - printf("uniform: %zu %f: %f secs\n", N, (double) sum / N, (float) diff / CLOCKS_PER_SEC); + + uint64_t sum = 0; cstc64_normalf_t dist2 = cstc64_normalf_init(R / 2.0, R / 6.0); size_t N2 = 10000000; int hist[R] = {0}; sum = 0; - before = clock(); c_forrange (N2) { - int n = (int) (cstc64_normalf(&stc, &dist2) + 0.5); + int n = round((cstc64_normalf(&stc, &dist2) + 0.5)); sum += n; if (n >= 0 && n < R) ++hist[n]; } - diff = clock() - before; - printf("normal : %zu %f: %f secs\n", N, (double) sum / N2, (float) diff / CLOCKS_PER_SEC); - cstr_t bar = cstr_inits; c_forrange (i, int, R) { cstr_resize(&bar, hist[i] * 25ull * R / N2, '*'); printf("%3d %s\n", i, bar.str); } + + clock_t diff, before; + + sum = 0; + before = clock(); + c_forrange (N) { + sum += cstc64_rand(&stc); + } + diff = clock() - before; + printf("random : %f secs, %zu %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); + + cstc64_uniform_t dist1 = cstc64_uniform_init(0, 1000); + sum = 0; + before = clock(); + c_forrange (N) { + sum += cstc64_uniform(&stc, &dist1); + } + diff = clock() - before; + printf("uniform: %f secs, %zu %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); + cstr_del(&bar); } \ No newline at end of file diff --git a/stc/crandom.h b/stc/crandom.h index fa353345..f0413abd 100644 --- a/stc/crandom.h +++ b/stc/crandom.h @@ -81,11 +81,6 @@ STC_API double cstc64_normalf(cstc64_t* rng, cstc64_normalf_t* dist); #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) -#if defined(_MSC_VER) - #pragma warning(push) - //#pragma warning(disable: 4146) -#endif - /* PRNG stc64: Tyge Løvset, NORCE Research, 2020. * Extremely fast PRNG suited for parallel usage with Weyl-sequence parameter. * Faster than sfc64, wyhash64, and almost 50% faster than xoshiro256** on gcc. @@ -143,9 +138,6 @@ STC_DEF double cstc64_normalf(cstc64_t* rng, cstc64_normalf_t* dist) { return (u1 * m) * dist->stddev + dist->mean; } -#if defined(_MSC_VER) - #pragma warning(pop) -#endif #endif #endif -- cgit v1.2.3