Skip to content

Commit 23d316f

Browse files
authored
bench: refactor to use dynamic memory allocation in maths/strided/special
PR-URL: #11697 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #8643
1 parent 2e01a60 commit 23d316f

File tree

29 files changed

+231
-77
lines changed

29 files changed

+231
-77
lines changed

lib/node_modules/@stdlib/math/strided/special/dmskabs/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -100.0, 100.0 );
126129
y[ i ] = 0.0;
@@ -138,6 +141,9 @@ static double benchmark( int iterations, int len ) {
138141
if ( y[ 0 ] != y[ 0 ] ) {
139142
printf( "should not return NaN\n" );
140143
}
144+
free( m );
145+
free( x );
146+
free( y );
141147
return elapsed;
142148
}
143149

lib/node_modules/@stdlib/math/strided/special/dmskabs2/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -100.0, 100.0 );
126129
y[ i ] = 0.0;
@@ -138,6 +141,9 @@ static double benchmark( int iterations, int len ) {
138141
if ( y[ 0 ] != y[ 0 ] ) {
139142
printf( "should not return NaN\n" );
140143
}
144+
free( m );
145+
free( x );
146+
free( y );
141147
return elapsed;
142148
}
143149

lib/node_modules/@stdlib/math/strided/special/dmskcbrt/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -100.0, 100.0 );
126129
y[ i ] = 0.0;
@@ -139,6 +142,9 @@ static double benchmark( int iterations, int len ) {
139142
if ( y[ 0 ] != y[ 0 ] ) {
140143
printf( "should not return NaN\n" );
141144
}
145+
free( m );
146+
free( x );
147+
free( y );
142148
return elapsed;
143149
}
144150

lib/node_modules/@stdlib/math/strided/special/dmskceil/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -10.0, 10.0 );
126129
y[ i ] = 0.0;
@@ -138,6 +141,9 @@ static double benchmark( int iterations, int len ) {
138141
if ( y[ 0 ] != y[ 0 ] ) {
139142
printf( "should not return NaN\n" );
140143
}
144+
free( m );
145+
free( x );
146+
free( y );
141147
return elapsed;
142148
}
143149

lib/node_modules/@stdlib/math/strided/special/dmskdeg2rad/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -180.0, 180.0 );
126129
y[ i ] = 0.0;
@@ -138,6 +141,9 @@ static double benchmark( int iterations, int len ) {
138141
if ( y[ 0 ] != y[ 0 ] ) {
139142
printf( "should not return NaN\n" );
140143
}
144+
free( m );
145+
free( x );
146+
free( y );
141147
return elapsed;
142148
}
143149

lib/node_modules/@stdlib/math/strided/special/dmskfloor/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -10.0, 10.0 );
126129
y[ i ] = 0.0;
@@ -138,6 +141,9 @@ static double benchmark( int iterations, int len ) {
138141
if ( y[ 0 ] != y[ 0 ] ) {
139142
printf( "should not return NaN\n" );
140143
}
144+
free( m );
145+
free( x );
146+
free( y );
141147
return elapsed;
142148
}
143149

lib/node_modules/@stdlib/math/strided/special/dmskinv/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -50.0, 50.0 );
126129
y[ i ] = 0.0;
@@ -138,6 +141,9 @@ static double benchmark( int iterations, int len ) {
138141
if ( y[ 0 ] != y[ 0 ] ) {
139142
printf( "should not return NaN\n" );
140143
}
144+
free( m );
145+
free( x );
146+
free( y );
141147
return elapsed;
142148
}
143149

lib/node_modules/@stdlib/math/strided/special/dmskramp/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( -10.0, 10.0 );
126129
y[ i ] = 0.0;
@@ -139,6 +142,9 @@ static double benchmark( int iterations, int len ) {
139142
if ( y[ 0 ] != y[ 0 ] ) {
140143
printf( "should not return NaN\n" );
141144
}
145+
free( m );
146+
free( x );
147+
free( y );
142148
return elapsed;
143149
}
144150

lib/node_modules/@stdlib/math/strided/special/dmsksqrt/benchmark/c/benchmark.length.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ float rand_uniformf( float a, float b ) {
115115
*/
116116
static double benchmark( int iterations, int len ) {
117117
double elapsed;
118-
uint8_t m[ len ];
119-
double x[ len ];
120-
double y[ len ];
118+
uint8_t *m;
119+
double *x;
120+
double *y;
121121
double t;
122122
int i;
123123

124+
m = (uint8_t *) malloc( len * sizeof( uint8_t ) );
125+
x = (double *) malloc( len * sizeof( double ) );
126+
y = (double *) malloc( len * sizeof( double ) );
124127
for ( i = 0; i < len; i++ ) {
125128
x[ i ] = rand_uniform( 0.0, 200.0 );
126129
y[ i ] = 0.0;
@@ -138,6 +141,9 @@ static double benchmark( int iterations, int len ) {
138141
if ( y[ 0 ] != y[ 0 ] ) {
139142
printf( "should not return NaN\n" );
140143
}
144+
free( m );
145+
free( x );
146+
free( y );
141147
return elapsed;
142148
}
143149

lib/node_modules/@stdlib/math/strided/special/sabs/benchmark/c/benchmark.length.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ static float rand_float( void ) {
9696
*/
9797
static double benchmark( int iterations, int len ) {
9898
double elapsed;
99-
float x[ len ];
100-
float y[ len ];
99+
float *x;
100+
float *y;
101101
double t;
102102
int i;
103103

104+
x = (float *) malloc( len * sizeof( float ) );
105+
y = (float *) malloc( len * sizeof( float ) );
104106
for ( i = 0; i < len; i++ ) {
105107
x[ i ] = ( rand_float()*200.0f ) - 100.0f;
106108
y[ i ] = 0.0f;
@@ -117,6 +119,8 @@ static double benchmark( int iterations, int len ) {
117119
if ( y[ 0 ] != y[ 0 ] ) {
118120
printf( "should not return NaN\n" );
119121
}
122+
free( x );
123+
free( y );
120124
return elapsed;
121125
}
122126

0 commit comments

Comments
 (0)