Changes in / [c831073:d859a30]


Ignore:
Location:
tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/.expect/PRNG.x64.txt

    rc831073 rd859a30  
    1 
    2 CFA xoshiro256pp
    31
    42                    PRNG()     PRNG(5)   PRNG(0,5)
     
    5856
    5957Sequential
    60 trials 20000000 buckets 100000 min 139 max 265 avg 200.0 std 14.1 rstd 7.0%
     58trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%
    6159
    6260Concurrent
    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%
     61trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%
     62trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%
     63trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%
     64trials 100000000 buckets 100000 min 875 max 1146 avg 1000.0 std 31.6 rstd 3.2%
    6765
    6866                   prng(t)   prng(t,5) prng(t,0,5)
  • tests/PRNG.cfa

    rc831073 rd859a30  
    88// Created On       : Wed Dec 29 09:38:12 2021
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Sat Apr 15 16:44:31 2023
    11 // Update Count     : 419
     10// Last Modified On : Wed Dec 21 20:39:59 2022
     11// Update Count     : 406
    1212//
    1313
     
    1515#include <stdlib.hfa>                                                                   // PRNG
    1616#include <clock.hfa>
     17#include <thread.hfa>
    1718#include <limits.hfa>                                                                   // MAX
    1819#include <math.hfa>                                                                             // sqrt
    1920#include <malloc.h>                                                                             // malloc_stats
    2021#include <locale.h>                                                                             // setlocale
    21 #include <thread.hfa>
    2222#include <mutex_stmt.hfa>
    2323
    24 #define xstr(s) str(s)
    25 #define str(s) #s
    26 
    27 #if defined( __x86_64__ ) || defined( __aarch64__ )             // 64-bit architecture
     24#ifdef __x86_64__                                                                               // 64-bit architecture
    2825#define PRNG PRNG64
    2926#else                                                                                                   // 32-bit architecture
    3027#define PRNG PRNG32
    3128#endif // __x86_64__
    32 
    33 //#define TIME
    3429
    3530#ifdef TIME                                                                                             // use -O2 -nodebug
     
    4338#endif // TIME
    4439
    45 static void avgstd( size_t trials, size_t buckets[] ) {
    46         size_t min = MAX, max = 0;
     40void avgstd( unsigned int buckets[] ) {
     41        unsigned int min = MAX, max = 0;
    4742        double sum = 0.0, diff;
    4843        for ( i; BUCKETS ) {
     
    5954        } // for
    6055        double std = sqrt( sum / BUCKETS );
    61         mutex( sout ) sout | "trials"  | trials | "buckets" | BUCKETS
     56        mutex( sout ) sout | "trials"  | TRIALS | "buckets" | BUCKETS
    6257                | "min" | min | "max" | max
    6358                | "avg" | wd(0,1, avg) | "std" | wd(0,1, std) | "rstd" | wd(0,1, (avg == 0 ? 0.0 : std / avg * 100)) | "%";
     
    6964thread T1 {};
    7065void main( T1 & ) {
    71         size_t * buckets = calloc( BUCKETS );                           // too big for task stack
    72         for ( TRIALS / 50 ) {
     66        unsigned int * buckets = calloc( BUCKETS );                     // too big for task stack
     67        for ( TRIALS / 100 ) {
    7368                buckets[rand() % BUCKETS] += 1;                                 // concurrent
    7469        } // for
    75         avgstd( TRIALS / 50, buckets );
     70        avgstd( buckets );
    7671        free( buckets );
    7772} // main
     
    8176        PRNG prng;
    8277        if ( seed != 0 ) set_seed( prng, seed );
    83         size_t * buckets = calloc( BUCKETS );                           // too big for task stack
     78        unsigned int * buckets = calloc( BUCKETS );                     // too big for task stack
    8479        for ( TRIALS ) {
    8580                buckets[prng( prng ) % BUCKETS] += 1;                   // concurrent
    8681        } // for
    87         avgstd( TRIALS, buckets );
     82        avgstd( buckets );
    8883        free( buckets );
    8984} // main
     
    9186thread T3 {};
    9287void main( T3 & th ) {
    93         size_t * buckets = calloc( BUCKETS );                           // too big for task stack
    94         for ( TRIALS / 5 ) {
     88        unsigned int * buckets = calloc( BUCKETS );                     // too big for task stack
     89        for ( TRIALS ) {
    9590                buckets[prng() % BUCKETS] += 1;                                 // concurrent
    9691        } // for
    97         avgstd( TRIALS / 5, buckets );
     92        avgstd( buckets );
    9893        free( buckets );
    9994} // main
     
    10196thread T4 {};
    10297void main( T4 & th ) {
    103         size_t * buckets = calloc( BUCKETS );                           // too big for task stack
     98        unsigned int * buckets = calloc( BUCKETS );                     // too big for task stack
    10499        for ( TRIALS ) {
    105                 buckets[prng( th ) % BUCKETS] += 1;                             // concurrent
    106         } // for
    107         avgstd( TRIALS, buckets );
     100                buckets[prng( th ) % BUCKETS] += 1;     // concurrent
     101        } // for
     102        avgstd( buckets );
    108103        free( buckets );
    109104} // main
     
    113108static void dummy( thread$ & th ) __attribute__(( noinline ));
    114109static void dummy( thread$ & th ) {
    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 ) {
     110        unsigned int * buckets = (unsigned int *)calloc( BUCKETS, sizeof(unsigned int) ); // too big for task stack
     111        for ( unsigned int i = 0; i < TRIALS; i += 1 ) {
    117112                buckets[prng( th ) % BUCKETS] += 1;                             // sequential
    118113        } // for
    119         avgstd( TRIALS, buckets );
     114        avgstd( buckets );
    120115        free( buckets );
    121116} // dummy
     
    131126        enum { TASKS = 4 };
    132127        Time start;
    133 
    134128#ifdef TIME                                                                                             // too slow for test and generates non-repeatable results
    135129#if 1
    136         sout | "glib rand" | nl | nl;
    137 
    138         size_t rseed;
     130        unsigned int rseed;
    139131        if ( seed != 0 ) rseed = seed;
    140132        else rseed = rdtscl();
     
    142134
    143135        sout | sepDisable;
    144         sout | nl | wd(26, "rand()" ) | wd(12, "rand(5)") | wd(12, "rand(0,5)" );
     136        sout | wd(26, "rand()" ) | wd(12, "rand(5)") | wd(12, "rand(0,5)" );
    145137        for ( 20 ) {
    146138                sout | wd(26, rand()) | nonl;
     
    154146        STARTTIME;
    155147        {
    156                 size_t * buckets = calloc( BUCKETS );                   // too big for task stack
    157                 for ( i; TRIALS / 5 ) {
     148                unsigned int * buckets = calloc( BUCKETS );             // too big for task stack
     149                for ( i; TRIALS / 10 ) {
    158150                        buckets[rand() % BUCKETS] += 1;                         // sequential
    159151                } // for
    160                 avgstd( TRIALS / 5, buckets );
     152                avgstd( buckets );
    161153                free( buckets );
    162154        }
    163         ENDTIME( " x 5 " );
     155        ENDTIME( " x 10 " );
    164156
    165157        sout | nl | "Concurrent";
     
    171163                } // wait for threads to complete
    172164        }
    173         ENDTIME( " x 50 " );
     165        ENDTIME( " x 100 " );
    174166#endif // 0
    175167#endif // TIME
    176 
    177         sout | nl | "CFA " xstr(PRNG_NAME);
    178 
    179168#if 1
    180169        PRNG prng;
     
    195184        STARTTIME;
    196185        {
    197                 size_t * buckets = calloc( BUCKETS );                   // too big for task stack
     186                unsigned int * buckets = calloc( BUCKETS );             // too big for task stack
    198187                for ( TRIALS ) {
    199188                        buckets[prng( prng ) % BUCKETS] += 1;           // sequential
    200189                } // for
    201                 avgstd( TRIALS, buckets );
     190                avgstd( buckets );
    202191                free( buckets );
    203192        }
     
    230219        STARTTIME;
    231220        {
    232                 size_t * buckets = calloc( BUCKETS );                   // too big for task stack
    233                 for ( TRIALS / 5 ) {
     221                unsigned int * buckets = calloc( BUCKETS );             // too big for task stack
     222                for ( TRIALS ) {
    234223                        buckets[prng() % BUCKETS] += 1;
    235224                } // for
    236                 avgstd( TRIALS / 5, buckets );
     225                avgstd( buckets );
    237226                free( buckets );
    238227        }
    239         ENDTIME( " x 5 " );
     228        ENDTIME();
    240229
    241230        sout | nl | "Concurrent";
     
    247236                } // wait for threads to complete
    248237        }
    249         ENDTIME( " x 5 " );
     238        ENDTIME();
    250239#endif // 0
    251240#if 1
Note: See TracChangeset for help on using the changeset viewer.