diff options
| author | Tyge Løvset <[email protected]> | 2020-12-15 22:14:10 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-12-15 22:14:10 +0100 |
| commit | 12d7c1b3ca437af8734acc8e7cbfdba08b8c36df (patch) | |
| tree | dd65b359860578c736be90b2ad0f2957beafd39b | |
| parent | a51861d02f9d8ed8c69fd243de18960307b0fd63 (diff) | |
| download | STC-modified-12d7c1b3ca437af8734acc8e7cbfdba08b8c36df.tar.gz STC-modified-12d7c1b3ca437af8734acc8e7cbfdba08b8c36df.zip | |
Minors on crandom and example.
| -rw-r--r-- | examples/random.c | 42 | ||||
| -rw-r--r-- | 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 <stdio.h>
#include <time.h>
+#include <math.h>
#include <stc/crandom.h>
#include <stc/cstr.h>
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
|
