Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -33,7 +33,7 @@
* Prints the TAP version.
*/
static void print_version( void ) {
printf( "TAP version 13\n" );
printf( "TAP version 13\n" );
}

/**
Expand All @@ -43,12 +43,12 @@ static void print_version( void ) {
* @param passing total number of passing tests
*/
static void print_summary( int total, int passing ) {
printf( "#\n" );
printf( "1..%d\n", total ); // TAP plan
printf( "# total %d\n", total );
printf( "# pass %d\n", passing );
printf( "#\n" );
printf( "# ok\n" );
printf( "#\n" );
printf( "1..%d\n", total ); // TAP plan
printf( "# total %d\n", total );
printf( "# pass %d\n", passing );
printf( "#\n" );
printf( "# ok\n" );
}

/**
Expand All @@ -58,12 +58,12 @@ static void print_summary( int total, int passing ) {
* @param elapsed elapsed time in seconds
*/
static void print_results( int iterations, double elapsed ) {
double rate = (double)iterations / elapsed;
printf( " ---\n" );
printf( " iterations: %d\n", iterations );
printf( " elapsed: %0.9f\n", elapsed );
printf( " rate: %0.9f\n", rate );
printf( " ...\n" );
double rate = (double)iterations / elapsed;
printf( " ---\n" );
printf( " iterations: %d\n", iterations );
printf( " elapsed: %0.9f\n", elapsed );
printf( " rate: %0.9f\n", rate );
printf( " ...\n" );
}

/**
Expand All @@ -72,9 +72,9 @@ static void print_results( int iterations, double elapsed ) {
* @return clock time
*/
static double tic( void ) {
struct timeval now;
gettimeofday( &now, NULL );
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
struct timeval now;
gettimeofday( &now, NULL );
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
}

/**
Expand All @@ -85,13 +85,13 @@ static double tic( void ) {
* @return random number
*/
double rand_uniform( double a, double b ) {
double x;
int r;
double x;
int r;

r = rand();
x = (double)r / ( (double)RAND_MAX + 1.0 );
r = rand();
x = (double)r / ( (double)RAND_MAX + 1.0 );

return ( b*x ) + ( (1.0-x)*a );
return ( b*x ) + ( (1.0-x)*a );
}

/**
Expand All @@ -102,7 +102,7 @@ double rand_uniform( double a, double b ) {
* @return random number
*/
float rand_uniformf( float a, float b ) {
return (float)rand_uniform( (double)a, (double)b );
return (float)rand_uniform( (double)a, (double)b );
}

/**
Expand All @@ -113,57 +113,75 @@ float rand_uniformf( float a, float b ) {
* @return elapsed time in seconds
*/
static double benchmark( int iterations, int len ) {
double elapsed;
float x[ len ];
float y[ len ];
double t;
int i;

for ( i = 0; i < len; i++ ) {
x[ i ] = rand_uniformf( -10.0f, 10.0f );
y[ i ] = 0.0f;
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
stdlib_strided_strunc( len, x, 1, y, 1 );
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
}
return elapsed;
double elapsed;
float *x;
float *y;
double t;
int i;

x = (float *)malloc( len * sizeof( float ) );
y = (float *)malloc( len * sizeof( float ) );

if ( x == NULL || y == NULL ) {
if ( x != NULL ) {
free( x );
}
if ( y != NULL ) {
free( y );
}
printf( "Error: unable to allocate memory.\n" );
exit( 1 );
}

for ( i = 0; i < len; i++ ) {
x[ i ] = rand_uniformf( -10.0f, 10.0f );
y[ i ] = 0.0f;
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
stdlib_strided_strunc( len, x, 1, y, 1 );
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
}

free( x );
free( y );

return elapsed;
}

/**
* Main execution sequence.
*/
int main( void ) {
double elapsed;
int count;
int iter;
int len;
int i;
int j;

// Use the current time to seed the random number generator:
srand( time( NULL ) );

print_version();
count = 0;
for ( i = MIN; i <= MAX; i++ ) {
len = pow( 10, i );
iter = ITERATIONS / pow( 10, i-1 );
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:len=%d\n", NAME, len );
elapsed = benchmark( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
}
print_summary( count, count );
}
double elapsed;
int count;
int iter;
int len;
int i;
int j;

// Use the current time to seed the random number generator:
srand( time( NULL ) );

print_version();
count = 0;
for ( i = MIN; i <= MAX; i++ ) {
len = pow( 10, i );
iter = ITERATIONS / pow( 10, i-1 );
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:len=%d\n", NAME, len );
elapsed = benchmark( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
}
print_summary( count, count );
}