summaryrefslogtreecommitdiffhomepage
path: root/examples/rngtest.c
diff options
context:
space:
mode:
authorTylo <[email protected]>2020-06-21 23:04:27 +0200
committerTylo <[email protected]>2020-06-21 23:04:27 +0200
commita44896e12d2fd51438b3620503e5db84d2f196e4 (patch)
tree4a1655ea95cdc1094ee3ea889b1e685a5d09eeb4 /examples/rngtest.c
parent63ee86b49299ab465781396aa9c464fb72bacd9a (diff)
downloadSTC-modified-a44896e12d2fd51438b3620503e5db84d2f196e4.tar.gz
STC-modified-a44896e12d2fd51438b3620503e5db84d2f196e4.zip
Moved examples to examples folder.
Diffstat (limited to 'examples/rngtest.c')
-rw-r--r--examples/rngtest.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/rngtest.c b/examples/rngtest.c
new file mode 100644
index 00000000..4a39c4e6
--- /dev/null
+++ b/examples/rngtest.c
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include <time.h>
+#include "../stc/crandom.h"
+#ifdef __cplusplus
+#include <random>
+#endif
+
+
+#define NN 1000000000
+
+int main(void)
+{
+ clock_t difference, before;
+ uint64_t v;
+ printf("start\n");
+
+ mt19937_t state = mt19937_default();
+ uint32_t k = mt19937_rand(&state);
+ printf("%u - %g\n", k, c_randToFloat(k));
+
+ before = clock(); \
+ v = 0;
+ for (size_t i=0; i<NN; i++) {
+ v += mt19937_rand(&state);
+ }
+ difference = clock() - before;
+ printf("my-mt: %.02f, %zu\n", (float) difference / CLOCKS_PER_SEC, v);
+
+#ifdef __cplusplus
+ std::mt19937 mt_rand;
+ before = clock(); \
+ v = 0;
+ for (size_t i=0; i<NN; i++) {
+ v += mt_rand();
+ }
+ difference = clock() - before;
+ printf("c++mt: %.02f, %zu\n", (float) difference / CLOCKS_PER_SEC, v);
+#endif
+
+ xoroshiro128ss_t xo = xoroshiro128ss_seed(1234);
+ before = clock(); \
+ v = 0;
+ for (size_t i=0; i<NN; i++) {
+ v += xoroshiro128ss_rand(&xo) & 0xffffffff;
+ }
+ difference = clock() - before;
+ printf("xoros: %.02f, %zu\n", (float) difference / CLOCKS_PER_SEC, v);
+
+
+ sfc64_t sfc = sfc64_seed(1234);
+ before = clock(); \
+ v = 0;
+ for (size_t i=0; i<NN; i++) {
+ v += sfc64_rand(&sfc) & 0xffffffff;
+ }
+ difference = clock() - before;
+ printf("sfc64: %.02f, %zu\n", (float) difference / CLOCKS_PER_SEC, v);
+
+/*
+ before = clock(); \
+ v = 0;
+ for (size_t i=0; i<NN; i++) {
+ v += rand();
+ }
+ difference = clock() - before;
+ printf("rand : %.02f, %zu\n", (float) difference / CLOCKS_PER_SEC, v);
+*/
+} \ No newline at end of file