source: Daodan/src/dSFMT/test.c@ 637

Last change on this file since 637 was 440, checked in by rossy, 15 years ago

int32rand

File size: 19.2 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <limits.h>
4#include <time.h>
5#include <string.h>
6#define DSFMT_DO_NOT_USE_OLD_NAMES
7#include "dSFMT.h"
8
9#define NUM_RANDS 50000
10#define TIC_MAG 1
11#define TIC_COUNT 2000
12
13w128_t dummy[NUM_RANDS / 2 + 1];
14
15typedef double (*genrand_t)(void);
16typedef double (*st_genrand_t)(dsfmt_t *dsfmt);
17typedef void (*fill_array_t)(double array[], int size);
18typedef void (*st_fill_array_t)(dsfmt_t *dsfmt, double array[], int size);
19
20#ifdef __GNUC__
21static void test_co(void) __attribute__((noinline));
22static void test_oc(void) __attribute__((noinline));
23static void test_oo(void) __attribute__((noinline));
24static void test_12(void) __attribute__((noinline));
25static void test_seq_co(void) __attribute__((noinline));
26static void test_seq_oc(void) __attribute__((noinline));
27static void test_seq_oo(void) __attribute__((noinline));
28static void test_seq_12(void) __attribute__((noinline));
29#else
30static void test_co(void);
31static void test_oc(void);
32static void test_oo(void);
33static void test_12(void);
34static void test_seq_co(void);
35static void test_seq_oc(void);
36static void test_seq_oo(void);
37static void test_seq_12(void);
38#endif
39static void check(char *start_mess, genrand_t genrand, fill_array_t fill_array,
40 st_genrand_t st_genrand, st_fill_array_t st_fill_array,
41 uint32_t seed, int n);
42static void check_ar(char *start_mess, genrand_t genrand,
43 fill_array_t fill_array,
44 st_genrand_t st_genrand,
45 st_fill_array_t st_fill_array,
46 int n);
47
48/* not inline wrapper functions for check() */
49static double s_genrand_close_open(void) {
50 return dsfmt_gv_genrand_close_open();
51}
52static double s_genrand_open_close(void) {
53 return dsfmt_gv_genrand_open_close();
54}
55static double s_genrand_open_open(void) {
56 return dsfmt_gv_genrand_open_open();
57}
58static double s_genrand_close1_open2(void) {
59 return dsfmt_gv_genrand_close1_open2();
60}
61static double sst_genrand_close_open(dsfmt_t *dsfmt) {
62 return dsfmt_genrand_close_open(dsfmt);
63}
64static double sst_genrand_open_close(dsfmt_t *dsfmt) {
65 return dsfmt_genrand_open_close(dsfmt);
66}
67static double sst_genrand_open_open(dsfmt_t *dsfmt) {
68 return dsfmt_genrand_open_open(dsfmt);
69}
70static double sst_genrand_close1_open2(dsfmt_t *dsfmt) {
71 return dsfmt_genrand_close1_open2(dsfmt);
72}
73static void s_fill_array_close_open(double array[], int size) {
74 dsfmt_gv_fill_array_close_open(array, size);
75}
76static void s_fill_array_open_close(double array[], int size) {
77 dsfmt_gv_fill_array_open_close(array, size);
78}
79static void s_fill_array_open_open(double array[], int size) {
80 dsfmt_gv_fill_array_open_open(array, size);
81}
82static void s_fill_array_close1_open2(double array[], int size) {
83 dsfmt_gv_fill_array_close1_open2(array, size);
84}
85static void sst_fill_array_close_open(dsfmt_t *dsfmt, double array[],
86 int size) {
87 dsfmt_fill_array_close_open(dsfmt, array, size);
88}
89static void sst_fill_array_open_close(dsfmt_t *dsfmt, double array[],
90 int size) {
91 dsfmt_fill_array_open_close(dsfmt, array, size);
92}
93static void sst_fill_array_open_open(dsfmt_t *dsfmt, double array[],
94 int size) {
95 dsfmt_fill_array_open_open(dsfmt, array, size);
96}
97static void sst_fill_array_close1_open2(dsfmt_t *dsfmt, double array[],
98 int size) {
99 dsfmt_fill_array_close1_open2(dsfmt, array, size);
100}
101
102static void check(char *range_str, genrand_t genrand, fill_array_t fill_array,
103 st_genrand_t st_genrand, st_fill_array_t st_fill_array,
104 uint32_t seed, int print_size) {
105 int i;
106 union W64_T {
107 uint64_t u;
108 double d;
109 };
110 w128_t little[DSFMT_N+1];
111 union W64_T *array = (union W64_T *)dummy;
112 union W64_T *plittle = (union W64_T *)little;
113 union W64_T r, r_st;
114 int lsize = DSFMT_N * 2 + 2;
115 dsfmt_t dsfmt;
116
117 printf("generated randoms %s\n", range_str);
118 dsfmt_gv_init_gen_rand(seed);
119 fill_array(&plittle[0].d, lsize);
120 fill_array(&array[0].d, 5000);
121 dsfmt_gv_init_gen_rand(seed);
122 dsfmt_init_gen_rand(&dsfmt, seed);
123 for (i = 0; i < lsize; i++) {
124 r.d = genrand();
125 r_st.d = st_genrand(&dsfmt);
126 if (r.u != r_st.u || r.u != plittle[i].u) {
127 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64"), "
128 "st = %1.15f(%08"PRIx64")"
129 "array = %1.15f(%08"PRIx64")\n",
130 range_str, i, r.d, r.u,
131 r_st.d, r_st.u,
132 plittle[i].d, plittle[i].u);
133 exit(1);
134 }
135 if (i < print_size) {
136 printf("%1.15f ", plittle[i].d);
137 if (i % 4 == 3) {
138 printf("\n");
139 }
140 }
141 }
142 for (i = 0; i < 5000; i++) {
143 r.d = genrand();
144 if (r.u != array[i].u) {
145 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64"), "
146 "array = %1.15f(%08"PRIx64")\n",
147 range_str, i + lsize, r.d, r.u,
148 array[i].d, array[i].u);
149 exit(1);
150 }
151 if (i + lsize < print_size) {
152 printf("%1.15f ", array[i].d);
153 if ((i + lsize) % 4 == 3) {
154 printf("\n");
155 }
156 }
157 }
158
159 dsfmt_init_gen_rand(&dsfmt, seed);
160 st_fill_array(&dsfmt, &plittle[0].d, lsize);
161 st_fill_array(&dsfmt, &array[0].d, 5000);
162 dsfmt_init_gen_rand(&dsfmt, seed);
163 for (i = 0; i < lsize; i++) {
164 r_st.d = st_genrand(&dsfmt);
165 if (r_st.u != plittle[i].u) {
166 printf("\n%s mismatch i = %d: st = %1.15f(%08"PRIx64"), "
167 "array = %1.15f(%08"PRIx64")\n",
168 range_str, i, r_st.d, r_st.u,
169 plittle[i].d, plittle[i].u);
170 exit(1);
171 }
172 }
173 for (i = 0; i < 5000; i++) {
174 r_st.d = st_genrand(&dsfmt);
175 if (r_st.u != array[i].u) {
176 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64"), "
177 "array = %1.15f(%08"PRIx64")\n",
178 range_str, i + lsize, r_st.d, r_st.u,
179 array[i].d, array[i].u);
180 exit(1);
181 }
182 }
183}
184
185static void check_ar(char *range_str, genrand_t genrand,
186 fill_array_t fill_array,
187 st_genrand_t st_genrand,
188 st_fill_array_t st_fill_array,
189 int print_size) {
190 int i;
191 union W64_T {
192 uint64_t u;
193 double d;
194 };
195 w128_t little[DSFMT_N+1];
196 union W64_T *array = (union W64_T *)dummy;
197 union W64_T *plittle = (union W64_T *)little;
198 union W64_T r, r_st;
199 int lsize = DSFMT_N * 2 + 2;
200 dsfmt_t dsfmt;
201 uint32_t ar[4] = {1, 2, 3, 4};
202
203 printf("generated randoms %s\n", range_str);
204 dsfmt_gv_init_by_array(ar, 4);
205 fill_array(&plittle[0].d, lsize);
206 fill_array(&array[0].d, 5000);
207 dsfmt_gv_init_by_array(ar, 4);
208 dsfmt_init_by_array(&dsfmt, ar, 4);
209 for (i = 0; i < lsize; i++) {
210 r.d = genrand();
211 r_st.d = st_genrand(&dsfmt);
212 if (r.u != r_st.u || r.u != plittle[i].u) {
213 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64"), "
214 "st = %1.15f(%08"PRIx64")"
215 "array = %1.15f(%08"PRIx64")\n",
216 range_str, i, r.d, r.u,
217 r_st.d, r_st.u,
218 plittle[i].d, plittle[i].u);
219 exit(1);
220 }
221 if (i < print_size) {
222 printf("%1.15f ", plittle[i].d);
223 if (i % 4 == 3) {
224 printf("\n");
225 }
226 }
227 }
228 for (i = 0; i < 5000; i++) {
229 r.d = genrand();
230 if (r.u != array[i].u) {
231 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64"), "
232 "array = %1.15f(%08"PRIx64")\n",
233 range_str, i + lsize, r.d, r.u,
234 array[i].d, array[i].u);
235 exit(1);
236 }
237 if (i + lsize < print_size) {
238 printf("%1.15f ", array[i].d);
239 if ((i + lsize) % 4 == 3) {
240 printf("\n");
241 }
242 }
243 }
244
245 dsfmt_init_by_array(&dsfmt, ar, 4);
246 st_fill_array(&dsfmt, &plittle[0].d, lsize);
247 st_fill_array(&dsfmt, &array[0].d, 5000);
248 dsfmt_init_by_array(&dsfmt, ar, 4);
249 for (i = 0; i < lsize; i++) {
250 r_st.d = st_genrand(&dsfmt);
251 if (r_st.u != plittle[i].u) {
252 printf("\n%s mismatch i = %d: st = %1.15f(%08"PRIx64"), "
253 "array = %1.15f(%08"PRIx64")\n",
254 range_str, i, r_st.d, r_st.u,
255 plittle[i].d, plittle[i].u);
256 exit(1);
257 }
258 }
259 for (i = 0; i < 5000; i++) {
260 r_st.d = st_genrand(&dsfmt);
261 if (r_st.u != array[i].u) {
262 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64"), "
263 "array = %1.15f(%08"PRIx64")\n",
264 range_str, i + lsize, r_st.d, r_st.u,
265 array[i].d, array[i].u);
266 exit(1);
267 }
268 }
269}
270
271static void test_co(void) {
272 uint32_t i, j;
273 uint64_t clo;
274 uint64_t sum;
275 double *array = (double *)dummy;
276 dsfmt_t dsfmt;
277
278#if 0
279 dsfmt_gv_init_gen_rand(1234);
280 sum = 0;
281 for (i = 0; i < 10; i++) {
282 clo = clock();
283 for (j = 0; j < TIC_COUNT; j++) {
284 dsfmt_gv_fill_array_close_open(array, NUM_RANDS);
285 }
286 clo = clock() - clo;
287 sum += clo;
288 }
289 printf("GL BLOCK [0, 1) AVE:%4"PRIu64"ms.\n",
290 (sum * 100) / CLOCKS_PER_SEC);
291#endif
292 dsfmt_init_gen_rand(&dsfmt, 1234);
293 sum = 0;
294 for (i = 0; i < 10; i++) {
295 clo = clock();
296 for (j = 0; j < TIC_COUNT; j++) {
297 dsfmt_fill_array_close_open(&dsfmt, array, NUM_RANDS);
298 }
299 clo = clock() - clo;
300 sum += clo;
301 }
302 printf("ST BLOCK [0, 1) AVE:%4"PRIu64"ms.\n",
303 (sum * 100) / CLOCKS_PER_SEC);
304}
305
306static void test_oc(void) {
307 uint32_t i, j;
308 uint64_t clo;
309 uint64_t sum;
310 double *array = (double *)dummy;
311 dsfmt_t dsfmt;
312#if 0
313 dsfmt_gv_init_gen_rand(1234);
314 sum = 0;
315 for (i = 0; i < 10; i++) {
316 clo = clock();
317 for (j = 0; j < TIC_COUNT; j++) {
318 dsfmt_gv_fill_array_open_close(array, NUM_RANDS);
319 }
320 clo = clock() - clo;
321 sum += clo;
322 }
323 printf("GL BLOCK (0, 1] AVE:%4"PRIu64"ms.\n",
324 (sum * 100) / CLOCKS_PER_SEC);
325#endif
326 dsfmt_init_gen_rand(&dsfmt, 1234);
327 sum = 0;
328 for (i = 0; i < 10; i++) {
329 clo = clock();
330 for (j = 0; j < TIC_COUNT; j++) {
331 dsfmt_fill_array_open_close(&dsfmt, array, NUM_RANDS);
332 }
333 clo = clock() - clo;
334 sum += clo;
335 }
336 printf("ST BLOCK (0, 1] AVE:%4"PRIu64"ms.\n",
337 (sum * 100) / CLOCKS_PER_SEC);
338}
339
340static void test_oo(void) {
341 uint32_t i, j;
342 uint64_t clo;
343 uint64_t sum;
344 double *array = (double *)dummy;
345 dsfmt_t dsfmt;
346#if 0
347 dsfmt_gv_init_gen_rand(1234);
348 sum = 0;
349 for (i = 0; i < 10; i++) {
350 clo = clock();
351 for (j = 0; j < TIC_COUNT; j++) {
352 dsfmt_gv_fill_array_open_open(array, NUM_RANDS);
353 }
354 clo = clock() - clo;
355 sum += clo;
356 }
357 printf("GL BLOCK (0, 1) AVE:%4"PRIu64"ms.\n",
358 (sum * 100) / CLOCKS_PER_SEC);
359#endif
360 dsfmt_init_gen_rand(&dsfmt, 1234);
361 sum = 0;
362 for (i = 0; i < 10; i++) {
363 clo = clock();
364 for (j = 0; j < TIC_COUNT; j++) {
365 dsfmt_fill_array_open_open(&dsfmt, array, NUM_RANDS);
366 }
367 clo = clock() - clo;
368 sum += clo;
369 }
370 printf("ST BLOCK (0, 1) AVE:%4"PRIu64"ms.\n",
371 (sum * 100) / CLOCKS_PER_SEC);
372}
373
374static void test_12(void) {
375 uint32_t i, j;
376 uint64_t clo;
377 uint64_t sum;
378 double *array = (double *)dummy;
379 dsfmt_t dsfmt;
380#if 0
381 dsfmt_gv_init_gen_rand(1234);
382 sum = 0;
383 for (i = 0; i < 10; i++) {
384 clo = clock();
385 for (j = 0; j < TIC_COUNT; j++) {
386 dsfmt_gv_fill_array_close1_open2(array, NUM_RANDS);
387 }
388 clo = clock() - clo;
389 sum += clo;
390 }
391 printf("GL BLOCK [1, 2) AVE:%4"PRIu64"ms.\n",
392 (sum * 100) / CLOCKS_PER_SEC);
393#endif
394 dsfmt_init_gen_rand(&dsfmt, 1234);
395 sum = 0;
396 for (i = 0; i < 10; i++) {
397 clo = clock();
398 for (j = 0; j < TIC_COUNT; j++) {
399 dsfmt_fill_array_close1_open2(&dsfmt, array, NUM_RANDS);
400 }
401 clo = clock() - clo;
402 sum += clo;
403 }
404 printf("ST BLOCK [1, 2) AVE:%4"PRIu64"ms.\n",
405 (sum * 100) / CLOCKS_PER_SEC);
406}
407
408static void test_seq_co(void) {
409 uint32_t i, j, k;
410 uint64_t clo;
411 uint64_t sum;
412 double *array = (double *)dummy;
413 double r;
414 double total = 0;
415 dsfmt_t dsfmt;
416#if 0
417 dsfmt_gv_init_gen_rand(1234);
418 sum = 0;
419 r = 0;
420 for (i = 0; i < 10; i++) {
421 clo = clock();
422 for (j = 0; j < TIC_COUNT; j++) {
423 for (k = 0; k < NUM_RANDS; k++) {
424 r += dsfmt_gv_genrand_close_open();
425 }
426 }
427 clo = clock() - clo;
428 sum += clo;
429 }
430 total = r;
431 printf("GL SEQ [0, 1) 1 AVE:%4"PRIu64"ms.\n",
432 (sum * 100) / CLOCKS_PER_SEC);
433
434 sum = 0;
435 for (i = 0; i < 10; i++) {
436 clo = clock();
437 for (j = 0; j < TIC_COUNT; j++) {
438 for (k = 0; k < NUM_RANDS; k++) {
439 array[k] = dsfmt_gv_genrand_close_open();
440 }
441 }
442 clo = clock() - clo;
443 sum += clo;
444 }
445 for (k = 0; k < NUM_RANDS; k++) {
446 total += array[k];
447 }
448 printf("GL SEQ [0, 1) 2 AVE:%4"PRIu64"ms.\n",
449 (sum * 100) / CLOCKS_PER_SEC);
450#endif
451 dsfmt_init_gen_rand(&dsfmt, 1234);
452 sum = 0;
453 r = 0;
454 for (i = 0; i < 10; i++) {
455 clo = clock();
456 for (j = 0; j < TIC_COUNT; j++) {
457 for (k = 0; k < NUM_RANDS; k++) {
458 r += dsfmt_genrand_close_open(&dsfmt);
459 }
460 }
461 clo = clock() - clo;
462 sum += clo;
463 }
464 total = r;
465 printf("ST SEQ [0, 1) 1 AVE:%4"PRIu64"ms.\n",
466 (sum * 100) / CLOCKS_PER_SEC);
467
468 sum = 0;
469 for (i = 0; i < 10; i++) {
470 clo = clock();
471 for (j = 0; j < TIC_COUNT; j++) {
472 for (k = 0; k < NUM_RANDS; k++) {
473 array[k] = dsfmt_genrand_close_open(&dsfmt);
474 }
475 }
476 clo = clock() - clo;
477 sum += clo;
478 }
479 for (k = 0; k < NUM_RANDS; k++) {
480 total += array[k];
481 }
482 printf("ST SEQ [0, 1) 2 AVE:%4"PRIu64"ms.\n",
483 (sum * 100) / CLOCKS_PER_SEC);
484
485 printf("total = %f\n", total);
486}
487
488static void test_seq_oc(void) {
489 uint32_t i, j, k;
490 uint64_t clo;
491 uint64_t sum;
492 double *array = (double *)dummy;
493 double r;
494 double total = 0;
495 dsfmt_t dsfmt;
496#if 0
497 dsfmt_gv_init_gen_rand(1234);
498 sum = 0;
499 r = 0;
500 for (i = 0; i < 10; i++) {
501 clo = clock();
502 for (j = 0; j < TIC_COUNT; j++) {
503 for (k = 0; k < NUM_RANDS; k++) {
504 r += dsfmt_gv_genrand_open_close();
505 }
506 }
507 clo = clock() - clo;
508 sum += clo;
509 }
510 total = r;
511 printf("GL SEQ (0, 1] 1 AVE:%4"PRIu64"ms.\n",
512 (sum * 100) / CLOCKS_PER_SEC);
513 sum = 0;
514 for (i = 0; i < 10; i++) {
515 clo = clock();
516 for (j = 0; j < TIC_COUNT; j++) {
517 for (k = 0; k < NUM_RANDS; k++) {
518 array[k] = dsfmt_gv_genrand_open_close();
519 }
520 }
521 clo = clock() - clo;
522 sum += clo;
523 }
524 for (k = 0; k < NUM_RANDS; k++) {
525 total += array[k];
526 }
527 printf("GL SEQ (0, 1] 2 AVE:%4"PRIu64"ms.\n",
528 (sum * 100) / CLOCKS_PER_SEC);
529#endif
530 dsfmt_init_gen_rand(&dsfmt, 1234);
531 sum = 0;
532 r = 0;
533 for (i = 0; i < 10; i++) {
534 clo = clock();
535 for (j = 0; j < TIC_COUNT; j++) {
536 for (k = 0; k < NUM_RANDS; k++) {
537 r += dsfmt_genrand_open_close(&dsfmt);
538 }
539 }
540 clo = clock() - clo;
541 sum += clo;
542 }
543 total += r;
544 printf("ST SEQ (0, 1] 1 AVE:%4"PRIu64"ms.\n",
545 (sum * 100) / CLOCKS_PER_SEC);
546 sum = 0;
547 for (i = 0; i < 10; i++) {
548 clo = clock();
549 for (j = 0; j < TIC_COUNT; j++) {
550 for (k = 0; k < NUM_RANDS; k++) {
551 array[k] = dsfmt_genrand_open_close(&dsfmt);
552 }
553 }
554 clo = clock() - clo;
555 sum += clo;
556 }
557 for (k = 0; k < NUM_RANDS; k++) {
558 total += array[k];
559 }
560 printf("ST SEQ (0, 1] 2 AVE:%4"PRIu64"ms.\n",
561 (sum * 100) / CLOCKS_PER_SEC);
562 printf("total = %f\n", total);
563}
564
565static void test_seq_oo(void) {
566 uint32_t i, j, k;
567 uint64_t clo;
568 uint64_t sum;
569 double *array = (double *)dummy;
570 double r;
571 double total = 0;
572 dsfmt_t dsfmt;
573#if 0
574 dsfmt_gv_init_gen_rand(1234);
575 sum = 0;
576 r = 0;
577 for (i = 0; i < 10; i++) {
578 clo = clock();
579 for (j = 0; j < TIC_COUNT; j++) {
580 for (k = 0; k < NUM_RANDS; k++) {
581 r += dsfmt_gv_genrand_open_open();
582 }
583 }
584 clo = clock() - clo;
585 sum += clo;
586 }
587 total = r;
588 printf("GL SEQ (0, 1) 1 AVE:%4"PRIu64"ms.\n",
589 (sum * 100) / CLOCKS_PER_SEC);
590 sum = 0;
591 for (i = 0; i < 10; i++) {
592 clo = clock();
593 for (j = 0; j < TIC_COUNT; j++) {
594 for (k = 0; k < NUM_RANDS; k++) {
595 array[k] = dsfmt_gv_genrand_open_open();
596 }
597 }
598 clo = clock() - clo;
599 sum += clo;
600 }
601 for (k = 0; k < NUM_RANDS; k++) {
602 total += array[k];
603 }
604 printf("GL SEQ (0, 1) 2 AVE:%4"PRIu64"ms.\n",
605 (sum * 100) / CLOCKS_PER_SEC);
606#endif
607 dsfmt_init_gen_rand(&dsfmt, 1234);
608 sum = 0;
609 r = 0;
610 for (i = 0; i < 10; i++) {
611 clo = clock();
612 for (j = 0; j < TIC_COUNT; j++) {
613 for (k = 0; k < NUM_RANDS; k++) {
614 r += dsfmt_genrand_open_open(&dsfmt);
615 }
616 }
617 clo = clock() - clo;
618 sum += clo;
619 }
620 total += r;
621 printf("ST SEQ (0, 1) 1 AVE:%4"PRIu64"ms.\n",
622 (sum * 100) / CLOCKS_PER_SEC);
623 sum = 0;
624 for (i = 0; i < 10; i++) {
625 clo = clock();
626 for (j = 0; j < TIC_COUNT; j++) {
627 for (k = 0; k < NUM_RANDS; k++) {
628 array[k] = dsfmt_genrand_open_open(&dsfmt);
629 }
630 }
631 clo = clock() - clo;
632 sum += clo;
633 }
634 for (k = 0; k < NUM_RANDS; k++) {
635 total += array[k];
636 }
637 printf("ST SEQ (0, 1) 2 AVE:%4"PRIu64"ms.\n",
638 (sum * 100) / CLOCKS_PER_SEC);
639 printf("total = %f\n", total);
640}
641
642static void test_seq_12(void) {
643 uint32_t i, j, k;
644 uint64_t clo;
645 uint64_t sum;
646 double *array = (double *)dummy;
647 double r;
648 double total = 0;
649 dsfmt_t dsfmt;
650#if 0
651 dsfmt_gv_init_gen_rand(1234);
652 sum = 0;
653 r = 0;
654 for (i = 0; i < 10; i++) {
655 clo = clock();
656 for (j = 0; j < TIC_COUNT; j++) {
657 for (k = 0; k < NUM_RANDS; k++) {
658 r += dsfmt_gv_genrand_close1_open2();
659 }
660 }
661 clo = clock() - clo;
662 sum += clo;
663 }
664 total = r;
665 printf("GL SEQ [1, 2) 1 AVE:%4"PRIu64"ms.\n",
666 (sum * 100) / CLOCKS_PER_SEC);
667 sum = 0;
668 for (i = 0; i < 10; i++) {
669 clo = clock();
670 for (j = 0; j < TIC_COUNT; j++) {
671 for (k = 0; k < NUM_RANDS; k++) {
672 array[k] = dsfmt_gv_genrand_close1_open2();
673 }
674 }
675 clo = clock() - clo;
676 sum += clo;
677 }
678 for (k = 0; k < NUM_RANDS; k++) {
679 total += array[k];
680 }
681 printf("GL SEQ [1, 2) 2 AVE:%4"PRIu64"ms.\n",
682 (sum * 100) / CLOCKS_PER_SEC);
683#endif
684 dsfmt_init_gen_rand(&dsfmt, 1234);
685 sum = 0;
686 r = 0;
687 for (i = 0; i < 10; i++) {
688 clo = clock();
689 for (j = 0; j < TIC_COUNT; j++) {
690 for (k = 0; k < NUM_RANDS; k++) {
691 r += dsfmt_genrand_close1_open2(&dsfmt);
692 }
693 }
694 clo = clock() - clo;
695 sum += clo;
696 }
697 total += r;
698 printf("ST SEQ [1, 2) 1 AVE:%4"PRIu64"ms.\n",
699 (sum * 100) / CLOCKS_PER_SEC);
700 sum = 0;
701 for (i = 0; i < 10; i++) {
702 clo = clock();
703 for (j = 0; j < TIC_COUNT; j++) {
704 for (k = 0; k < NUM_RANDS; k++) {
705 array[k] = dsfmt_genrand_close1_open2(&dsfmt);
706 }
707 }
708 clo = clock() - clo;
709 sum += clo;
710 }
711 for (k = 0; k < NUM_RANDS; k++) {
712 total += array[k];
713 }
714 printf("ST SEQ [1, 2) 2 AVE:%4"PRIu64"ms.\n",
715 (sum * 100) / CLOCKS_PER_SEC);
716 printf("total = %f\n", total);
717}
718
719int main(int argc, char *argv[]) {
720 int i;
721
722 if ((argc >= 2) && (strncmp(argv[1],"-s",2) == 0)) {
723 printf("consumed time for generating %d randoms.\n",
724 NUM_RANDS * TIC_COUNT);
725 test_co();
726 test_oc();
727 test_oo();
728 test_12();
729 test_seq_co();
730 test_seq_oc();
731 test_seq_oo();
732 test_seq_12();
733 } else {
734 printf("%s\n", dsfmt_get_idstring());
735 printf("init_gen_rand(0) ");
736 check("[1, 2)", s_genrand_close1_open2, s_fill_array_close1_open2,
737 sst_genrand_close1_open2, sst_fill_array_close1_open2, 0, 1000);
738 for (i = 0; i < 20; i++) {
739 printf("init_gen_rand(%d) ", i);
740 switch (i % 4) {
741 case 0:
742 check("[0, 1)", s_genrand_close_open, s_fill_array_close_open,
743 sst_genrand_close_open, sst_fill_array_close_open, i, 12);
744 break;
745 case 1:
746 check("(0, 1]", s_genrand_open_close, s_fill_array_open_close,
747 sst_genrand_open_close, sst_fill_array_open_close, i, 12);
748 break;
749 case 2:
750 check("(0, 1)", s_genrand_open_open, s_fill_array_open_open,
751 sst_genrand_open_open, sst_fill_array_open_open, i, 12);
752 break;
753 case 3:
754 default:
755 check("[1, 2)", s_genrand_close1_open2,
756 s_fill_array_close1_open2,
757 sst_genrand_close1_open2,
758 sst_fill_array_close1_open2, i, 12);
759 }
760 }
761 printf("init_by_array {1, 2, 3, 4} ");
762 check_ar("[1, 2)", s_genrand_close1_open2,
763 s_fill_array_close1_open2,
764 sst_genrand_close1_open2,
765 sst_fill_array_close1_open2,
766 1000);
767 }
768 return 0;
769}
Note: See TracBrowser for help on using the repository browser.