/////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// import std.c.time; import sfmt; extern (C) { void exit ( int status ); int strncmp ( char str1, char[] str2, size_t num ); const int BLOCK_SIZE = 100000; const int BLOCK_SIZE64 = 50000; const int COUNT = 1000; static uint64_t array1[BLOCK_SIZE / 4][2]; static uint64_t array2[10000 / 4][2]; void check32() { int i; uint32_t *array32 = cast(uint32_t *)array1; uint32_t *array32_2 = cast(uint32_t *)array2; uint32_t[4] ini = [0x1234, 0x5678, 0x9abc, 0xdef0]; uint32_t r32; if (get_min_array_size32() > 10000) { printf("array size too small!\n"); exit(1); } printf("%*s\n32 bit generated randoms\n", get_idstring()); printf("init_gen_rand__________\n"); /* 32 bit generation */ init_gen_rand(1234); fill_array32(array32, 10000); fill_array32(array32_2, 10000); init_gen_rand(1234); for (i = 0; i < 10000; i++) { if (i < 1000) { printf("%10u ", array32[i]); if (i % 5 == 4) { printf("\n"); } } r32 = gen_rand32(); if (r32 != array32[i]) { printf("\nmismatch at %d array32:%x gen:%x\n", i, array32[i], r32); exit(1); } } for (i = 0; i < 700; i++) { r32 = gen_rand32(); if (r32 != array32_2[i]) { printf("\nmismatch at %d array32_2:%x gen:%x\n", i, array32_2[i], r32); exit(1); } } printf("\n"); init_by_array(ini, 4); printf("init_by_array__________\n"); fill_array32(array32, 10000); fill_array32(array32_2, 10000); init_by_array(ini, 4); for (i = 0; i < 10000; i++) { if (i < 1000) { printf("%10u ", array32[i]); if (i % 5 == 4) { printf("\n"); } } r32 = gen_rand32(); if (r32 != array32[i]) { printf("\nmismatch at %d array32:%x gen:%x\n", i, array32[i], r32); exit(1); } } for (i = 0; i < 700; i++) { r32 = gen_rand32(); if (r32 != array32_2[i]) { printf("\nmismatch at %d array32_2:%x gen:%x\n", i, array32_2[i], r32); exit(1); } } } void speed32() { int i, j; clock_t clo; clock_t min = int.max; uint32_t *array32 = cast(uint32_t *)array1; if (get_min_array_size32() > BLOCK_SIZE) { printf("array size too small!\n"); exit(1); } /* 32 bit generation */ init_gen_rand(1234); for (i = 0; i < 10; i++) { clo = clock(); for (j = 0; j < COUNT; j++) { fill_array32(array32, BLOCK_SIZE); } clo = clock() - clo; if (clo < min) { min = clo; } } printf("32 bit BLOCK:%.0f", cast(double)min * 1000/ CLOCKS_PER_SEC); printf("ms for %u randoms generation\n", BLOCK_SIZE * COUNT); min = int.max; init_gen_rand(1234); for (i = 0; i < 10; i++) { clo = clock(); for (j = 0; j < BLOCK_SIZE * COUNT; j++) { gen_rand32(); } clo = clock() - clo; if (clo < min) { min = clo; } } printf("32 bit SEQUE:%.0f", cast(double)min * 1000 / CLOCKS_PER_SEC); printf("ms for %u randoms generation\n", BLOCK_SIZE * COUNT); } } import std.stdio; void main(char[][] args) { int i; int speed = 0; int bit32 = 0; int bit64 = 0; foreach (argc, argv; args) { if (argv == "-s") { speed = 1; } if (argv == "-b32") { bit32 = 1; } } if (speed + bit32 + bit64 == 0) { printf("usage:\n%*s [-s | -b32 | -b64]\n", args[0]); return 0; } if (speed) { speed32(); } if (bit32) { check32(); } //writefln(gen_rand32()); }