Skip to content

Commit 1870c91

Browse files
committed
bench: refactor to use dynamic memory allocation in blas/base/cswap
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 53ce62b commit 1870c91

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

lib/node_modules/@stdlib/blas/base/cswap/benchmark/c/benchmark.length.c

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

104+
x = (float *) malloc( len * 2 * sizeof( float ) );
105+
y = (float *) malloc( len * 2 * sizeof( float ) );
104106
for ( i = 0; i < len; i++ ) {
105107
x[ i ] = ( rand_float()*10000.0f ) - 5000.0f;
106108
x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f;
@@ -119,6 +121,8 @@ static double benchmark1( int iterations, int len ) {
119121
if ( y[ 0 ] != y[ 0 ] ) {
120122
printf( "should not return NaN\n" );
121123
}
124+
free( x );
125+
free( y );
122126
return elapsed;
123127
}
124128

@@ -131,11 +135,13 @@ static double benchmark1( int iterations, int len ) {
131135
*/
132136
static double benchmark2( int iterations, int len ) {
133137
double elapsed;
134-
float x[ len*2 ];
135-
float y[ len*2 ];
138+
float *x;
139+
float *y;
136140
double t;
137141
int i;
138142

143+
x = (float *) malloc( len * 2 * sizeof( float ) );
144+
y = (float *) malloc( len * 2 * sizeof( float ) );
139145
for ( i = 0; i < len; i++ ) {
140146
x[ i ] = ( rand_float()*10000.0f ) - 5000.0f;
141147
x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f;
@@ -154,6 +160,8 @@ static double benchmark2( int iterations, int len ) {
154160
if ( y[ 0 ] != y[ 0 ] ) {
155161
printf( "should not return NaN\n" );
156162
}
163+
free( x );
164+
free( y );
157165
return elapsed;
158166
}
159167

0 commit comments

Comments
 (0)