From a8ad541bfb79642eada22c1fd8d933d4fd45b05f Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Tue, 21 May 2002 23:11:09 +0000 Subject: [PATCH] Functions to test integer, floating point, bandwidth speeds, and cache size. svn path=/trunk/boinc/; revision=47 --- client/speed_stats.C | 418 +++++++++++++++++++++++++++++++++++++++++++ client/speed_stats.h | 32 ++++ 2 files changed, 450 insertions(+) create mode 100644 client/speed_stats.C create mode 100644 client/speed_stats.h diff --git a/client/speed_stats.C b/client/speed_stats.C new file mode 100644 index 0000000000..1f332aa54a --- /dev/null +++ b/client/speed_stats.C @@ -0,0 +1,418 @@ + + +#include +#include +#include +#include +#include "speed_stats.h" + +#ifdef RUN_TEST + +int main( void ) { + int cache_size; + + cache_size = check_cache_size( CACHE_MAX ); + + run_test_suite( 4 ); + + return 0; +} + +#endif + +int check_cache_size( int mem_size ) { + int i, n, index, stride, *memBlock, logStride, logCache; + double **results; + int steps, tsteps, csize, limit, temp, cind, sind; + clock_t total_sec, sec; + double secs, nanosecs, secs_per_test = 0.3, temp2; + int not_found; + + logStride = (int)(log(STRIDE_MAX/STRIDE_MIN)/log(2))+1; + logCache = (int)(log(CACHE_MAX/CACHE_MIN)/log(2))+1; + + printf( "Test will take about %.2f seconds.\n", SECS_PER_RUN*logStride*logCache ); + results = (double **)malloc( sizeof( double * )*logStride ); + + for( i=0;i0;n-- ) { + results[i][n] /= results[i][n-1]; + } + } + + for( i=0;i 1.5 ) { + printf( "Level 2 Data Cache is %d KB.\n", csize*sizeof(int)/CACHE_MIN ); + not_found = 0; + } + if( not_found == 2 && results[0][i] > 1.5 ) { + printf( "Level 1 Data Cache is %d KB.\n", csize*sizeof(int)/CACHE_MIN ); + not_found = 1; + } + i++; + csize *= 2; + } + + free( memBlock ); + for( i=0;i D_FLOP_ITERS ) /* no need to redo test */ + df_test_time = (int)double_flop_test( df_iters, 0 ); + else + df_iters = D_FLOP_ITERS; + + df_secs = (double)df_test_time/CLOCKS_PER_SEC; + + return 1000000*df_iters/df_secs; +} + +double run_int_test( double num_secs ) { + int int_test_time, int_iters; + double int_secs; + + /* Start by doing some quick timing tests for rough calibration */ + int_test_time = (int)int_op_test( I_OP_ITERS, 0 ); + if( int_test_time <= 0 ) int_test_time = 1; + int_secs = (double)int_test_time/CLOCKS_PER_SEC; + + /* Calculate the # of iterations based on these tests */ + int_iters = (int)(I_OP_ITERS*num_secs/int_secs); + + if( int_iters > I_OP_ITERS ) /* no need to redo test */ + int_test_time = (int)int_op_test( int_iters, 0 ); + else + int_iters = I_OP_ITERS; + + int_secs = (double)int_test_time/CLOCKS_PER_SEC; + + return 1000000*int_iters/int_secs; +} + +double run_mem_bandwidth_test( double num_secs ) { + int bw_test_time; + double bw_secs; + int bw_iters; + + /* Start by doing some quick timing tests for rough calibration */ + bw_test_time = (int)bandwidth_test( BANDWIDTH_ITERS, 0 ); + if( bw_test_time <= 0 ) bw_test_time = 1; + bw_secs = (double)bw_test_time/CLOCKS_PER_SEC; + + /* Calculate the # of iterations based on these tests */ + bw_iters = (int)(BANDWIDTH_ITERS*num_secs/bw_secs); + + if( bw_iters > BANDWIDTH_ITERS ) /* no need to redo test */ + bw_test_time = (int)bandwidth_test( bw_iters, 0 ); + else + bw_iters = BANDWIDTH_ITERS; + + bw_secs = (double)bw_test_time/CLOCKS_PER_SEC; + return 1000000*bw_iters/bw_secs; +} + +void run_test_suite( double num_secs_per_test ) { + int bw_test_time; + double bw_secs; + int bw_iters; + + printf( "Running tests. This will take about %.1lf seconds.\n\n", num_secs_per_test*3 ); + + printf( "Speed: %.5lf million flops/sec\n\n", run_double_prec_test(num_secs_per_test)/1000000 ); + printf( "Speed: %.5lf million integer ops/sec\n\n", run_int_test(num_secs_per_test)/1000000 ); + printf( "Speed: %.5lf MB/sec\n\n", 12*sizeof(double)*run_mem_bandwidth_test(num_secs_per_test)/1000000 ); +} + +/* One iteration == D_LOOP_ITERS (1,000,000) floating point operations */ + +clock_t double_flop_test( int iterations, int print_debug ) { + double a[NUM_DOUBLES],t1,t2; + double temp; + clock_t time_start, time_total; + int i,j,k,calc_error; + + /* Initialize the array */ + a[0] = 1; + for( i=1;i=0;k-- ) { + a[k] += 6; /* 2 int ops */ + } + for( k=0;k=0;k-- ) { + a[k] -= 2; /* 2 int ops */ + } + /*for( k=NUM_INTS-1;k>0;k-- ) { + a[k] -= a[k-1]; + } + for( k=1;k0;k-- ) { + a[k] /= a[k-1]; + } + a[0] /= 2; + for( k=1;k time_start ) + time_total -= time_start; + else + time_total -= time_start; + + copy_error = 0; + for( i=0;i