Skip to content

Commit d1264e9

Browse files
committed
feat: updated C benchmarks with precomputation
1 parent 1605261 commit d1264e9

File tree

1 file changed

+12
-9
lines changed
  • lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native

1 file changed

+12
-9
lines changed

lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/native/benchmark.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,30 @@ static float rand_float( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
float x;
95-
float y;
96-
float z;
94+
float a[ 100 ];
95+
float b[ 100 ];
9796
double t;
97+
float y;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
a[ i ] = roundf( 500.0f * rand_float() );
102+
b[ i ] = roundf( 500.0f * rand_float() );
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = round( rand_float() * 500.0f );
103-
y = round( rand_float() * 500.0f );
104-
z = stdlib_base_lcmf( x, y );
105-
if ( z != z ) {
107+
y = stdlib_base_lcmf( a[ i % 100 ], b[ i % 100 ] );
108+
if ( y != y ) {
106109
printf( "should not return NaN\n" );
107110
break;
108111
}
109112
}
110113
elapsed = tic() - t;
111-
if ( z != z ) {
114+
if ( y != y ) {
112115
printf( "should not return NaN\n" );
113116
}
114-
return elapsed;
117+
return elapsed;
115118
}
116119

117120
/**

0 commit comments

Comments
 (0)