Skip to content

Commit 923a355

Browse files
committed
bench: refactor C benchmarks
1 parent 2b30eb7 commit 923a355

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/benchmark.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ static double rand_double( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
double x;
93+
double x[ 10 ];
9494
double y;
9595
double t;
9696
int i;
9797

98+
for ( i = 0; i < 10; i++ ) {
99+
x[ i ] = ( 10000.0*rand_double() ) - 0.0;
100+
}
98101
t = tic();
99102
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 10000.0*rand_double() ) - 0.0;
101-
y = log( x );
103+
y = log( x[ i%10 ] );
102104
if ( y != y ) {
103105
printf( "should not return NaN\n" );
104106
break;

lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/cephes/benchmark.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,17 @@ static double rand_double( void ) {
9595
*/
9696
static double benchmark( void ) {
9797
double elapsed;
98-
double x;
98+
double x[ 10 ];
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 10; i++ ) {
104+
x[ i ] = ( 10000.0*rand_double() ) - 0.0;
105+
}
103106
t = tic();
104107
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = ( 10000.0*rand_double() ) - 0.0;
106-
y = log( x );
108+
y = log( x[ i%10 ] );
107109
if ( y != y ) {
108110
printf( "should not return NaN\n" );
109111
break;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,17 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double x;
94+
double x[ 10 ];
9595
double y;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 10; i++ ) {
100+
x[ i ] = ( 10000.0*rand_double() ) - 0.0;
101+
}
99102
t = tic();
100103
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 10000.0*rand_double() ) - 0.0;
102-
y = stdlib_base_ln( x );
104+
y = stdlib_base_ln( x[ i%10 ] );
103105
if ( y != y ) {
104106
printf( "should not return NaN\n" );
105107
break;

0 commit comments

Comments
 (0)