Changeset 8a2f7f1
 Timestamp:
 Apr 15, 2023, 4:52:59 PM (8 months ago)
 Branches:
 ADT, astexperimental, master
 Children:
 c831073
 Parents:
 1b8fc06c
 Location:
 tests
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

tests/.expect/PRNG.x64.txt
r1b8fc06c r8a2f7f1 1 2 CFA xoshiro256pp 1 3 2 4 PRNG() PRNG(5) PRNG(0,5) … … 56 58 57 59 Sequential 58 trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%60 trials 20000000 buckets 100000 min 139 max 265 avg 200.0 std 14.1 rstd 7.0% 59 61 60 62 Concurrent 61 trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%62 trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%63 trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%64 trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%63 trials 20000000 buckets 100000 min 139 max 265 avg 200.0 std 14.1 rstd 7.0% 64 trials 20000000 buckets 100000 min 139 max 265 avg 200.0 std 14.1 rstd 7.0% 65 trials 20000000 buckets 100000 min 139 max 265 avg 200.0 std 14.1 rstd 7.0% 66 trials 20000000 buckets 100000 min 139 max 265 avg 200.0 std 14.1 rstd 7.0% 65 67 66 68 prng(t) prng(t,5) prng(t,0,5) 
tests/PRNG.cfa
r1b8fc06c r8a2f7f1 8 8 // Created On : Wed Dec 29 09:38:12 2021 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Wed Dec 21 20:39:59 202211 // Update Count : 4 0610 // Last Modified On : Sat Apr 15 16:44:31 2023 11 // Update Count : 419 12 12 // 13 13 … … 15 15 #include <stdlib.hfa> // PRNG 16 16 #include <clock.hfa> 17 #include <thread.hfa>18 17 #include <limits.hfa> // MAX 19 18 #include <math.hfa> // sqrt 20 19 #include <malloc.h> // malloc_stats 21 20 #include <locale.h> // setlocale 21 #include <thread.hfa> 22 22 #include <mutex_stmt.hfa> 23 23 24 #ifdef __x86_64__ // 64bit architecture 24 #define xstr(s) str(s) 25 #define str(s) #s 26 27 #if defined( __x86_64__ )  defined( __aarch64__ ) // 64bit architecture 25 28 #define PRNG PRNG64 26 29 #else // 32bit architecture 27 30 #define PRNG PRNG32 28 31 #endif // __x86_64__ 32 33 //#define TIME 29 34 30 35 #ifdef TIME // use O2 nodebug … … 38 43 #endif // TIME 39 44 40 void avgstd( unsigned int buckets[] ) {41 unsigned int min = MAX, max = 0;45 static void avgstd( size_t trials, size_t buckets[] ) { 46 size_t min = MAX, max = 0; 42 47 double sum = 0.0, diff; 43 48 for ( i; BUCKETS ) { … … 54 59 } // for 55 60 double std = sqrt( sum / BUCKETS ); 56 mutex( sout ) sout  "trials"  TRIALS "buckets"  BUCKETS61 mutex( sout ) sout  "trials"  trials  "buckets"  BUCKETS 57 62  "min"  min  "max"  max 58 63  "avg"  wd(0,1, avg)  "std"  wd(0,1, std)  "rstd"  wd(0,1, (avg == 0 ? 0.0 : std / avg * 100))  "%"; … … 64 69 thread T1 {}; 65 70 void main( T1 & ) { 66 unsigned int * buckets = calloc( BUCKETS );// too big for task stack67 for ( TRIALS / 100 ) {71 size_t * buckets = calloc( BUCKETS ); // too big for task stack 72 for ( TRIALS / 50 ) { 68 73 buckets[rand() % BUCKETS] += 1; // concurrent 69 74 } // for 70 avgstd( buckets );75 avgstd( TRIALS / 50, buckets ); 71 76 free( buckets ); 72 77 } // main … … 76 81 PRNG prng; 77 82 if ( seed != 0 ) set_seed( prng, seed ); 78 unsigned int * buckets = calloc( BUCKETS );// too big for task stack83 size_t * buckets = calloc( BUCKETS ); // too big for task stack 79 84 for ( TRIALS ) { 80 85 buckets[prng( prng ) % BUCKETS] += 1; // concurrent 81 86 } // for 82 avgstd( buckets );87 avgstd( TRIALS, buckets ); 83 88 free( buckets ); 84 89 } // main … … 86 91 thread T3 {}; 87 92 void main( T3 & th ) { 88 unsigned int * buckets = calloc( BUCKETS );// too big for task stack89 for ( TRIALS ) {93 size_t * buckets = calloc( BUCKETS ); // too big for task stack 94 for ( TRIALS / 5 ) { 90 95 buckets[prng() % BUCKETS] += 1; // concurrent 91 96 } // for 92 avgstd( buckets );97 avgstd( TRIALS / 5, buckets ); 93 98 free( buckets ); 94 99 } // main … … 96 101 thread T4 {}; 97 102 void main( T4 & th ) { 98 unsigned int * buckets = calloc( BUCKETS );// too big for task stack103 size_t * buckets = calloc( BUCKETS ); // too big for task stack 99 104 for ( TRIALS ) { 100 buckets[prng( th ) % BUCKETS] += 1; // concurrent101 } // for 102 avgstd( buckets );105 buckets[prng( th ) % BUCKETS] += 1; // concurrent 106 } // for 107 avgstd( TRIALS, buckets ); 103 108 free( buckets ); 104 109 } // main … … 108 113 static void dummy( thread$ & th ) __attribute__(( noinline )); 109 114 static void dummy( thread$ & th ) { 110 unsigned int * buckets = (unsigned int *)calloc( BUCKETS, sizeof(unsigned int) ); // too big for task stack111 for ( unsigned int i = 0; i < TRIALS; i += 1 ) {115 size_t * buckets = (size_t *)calloc( BUCKETS, sizeof(size_t) ); // too big for task stack 116 for ( size_t i = 0; i < TRIALS; i += 1 ) { 112 117 buckets[prng( th ) % BUCKETS] += 1; // sequential 113 118 } // for 114 avgstd( buckets );119 avgstd( TRIALS, buckets ); 115 120 free( buckets ); 116 121 } // dummy … … 126 131 enum { TASKS = 4 }; 127 132 Time start; 133 128 134 #ifdef TIME // too slow for test and generates nonrepeatable results 129 135 #if 1 130 unsigned int rseed; 136 sout  "glib rand"  nl  nl; 137 138 size_t rseed; 131 139 if ( seed != 0 ) rseed = seed; 132 140 else rseed = rdtscl(); … … 134 142 135 143 sout  sepDisable; 136 sout  wd(26, "rand()" )  wd(12, "rand(5)")  wd(12, "rand(0,5)" );144 sout  nl  wd(26, "rand()" )  wd(12, "rand(5)")  wd(12, "rand(0,5)" ); 137 145 for ( 20 ) { 138 146 sout  wd(26, rand())  nonl; … … 146 154 STARTTIME; 147 155 { 148 unsigned int * buckets = calloc( BUCKETS );// too big for task stack149 for ( i; TRIALS / 10) {156 size_t * buckets = calloc( BUCKETS ); // too big for task stack 157 for ( i; TRIALS / 5 ) { 150 158 buckets[rand() % BUCKETS] += 1; // sequential 151 159 } // for 152 avgstd( buckets );160 avgstd( TRIALS / 5, buckets ); 153 161 free( buckets ); 154 162 } 155 ENDTIME( " x 10" );163 ENDTIME( " x 5 " ); 156 164 157 165 sout  nl  "Concurrent"; … … 163 171 } // wait for threads to complete 164 172 } 165 ENDTIME( " x 100 " );173 ENDTIME( " x 50 " ); 166 174 #endif // 0 167 175 #endif // TIME 176 177 sout  nl  "CFA " xstr(PRNG_NAME); 178 168 179 #if 1 169 180 PRNG prng; … … 184 195 STARTTIME; 185 196 { 186 unsigned int * buckets = calloc( BUCKETS );// too big for task stack197 size_t * buckets = calloc( BUCKETS ); // too big for task stack 187 198 for ( TRIALS ) { 188 199 buckets[prng( prng ) % BUCKETS] += 1; // sequential 189 200 } // for 190 avgstd( buckets );201 avgstd( TRIALS, buckets ); 191 202 free( buckets ); 192 203 } … … 219 230 STARTTIME; 220 231 { 221 unsigned int * buckets = calloc( BUCKETS );// too big for task stack222 for ( TRIALS ) {232 size_t * buckets = calloc( BUCKETS ); // too big for task stack 233 for ( TRIALS / 5 ) { 223 234 buckets[prng() % BUCKETS] += 1; 224 235 } // for 225 avgstd( buckets );236 avgstd( TRIALS / 5, buckets ); 226 237 free( buckets ); 227 238 } 228 ENDTIME( );239 ENDTIME( " x 5 " ); 229 240 230 241 sout  nl  "Concurrent"; … … 236 247 } // wait for threads to complete 237 248 } 238 ENDTIME( );249 ENDTIME( " x 5 " ); 239 250 #endif // 0 240 251 #if 1
Note: See TracChangeset
for help on using the changeset viewer.