Skip to content

Commit d453db8

Browse files
fix: c benchmark
--- 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 a607bcf commit d453db8

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2026 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -97,11 +97,17 @@ static double rand_double( void ) {
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
9999
double out[ 4 ];
100-
double a[ len ];
101-
double b[ len ];
100+
double *a;
101+
double *b;
102102
double t;
103103
int i;
104104

105+
a = (double *)malloc( len * sizeof( double ) );
106+
b = (double *)malloc( len * sizeof( double ) );
107+
if ( a == NULL || b == NULL ) {
108+
printf( "Error: failed to allocate memory\n" );
109+
return -1.0;
110+
}
105111
for ( i = 0; i < len; i++ ) {
106112
a[ i ] = ( rand_double() * 200.0 ) - 100.0;
107113
b[ i ] = ( rand_double() * 200.0 ) - 100.0;
@@ -118,6 +124,8 @@ static double benchmark1( int iterations, int len ) {
118124
if ( out[ 0 ] != out[ 0 ] ) {
119125
printf( "should not return NaN\n" );
120126
}
127+
free( a );
128+
free( b );
121129
return elapsed;
122130
}
123131

@@ -131,11 +139,17 @@ static double benchmark1( int iterations, int len ) {
131139
static double benchmark2( int iterations, int len ) {
132140
double elapsed;
133141
double out[ 4 ];
134-
double a[ len ];
135-
double b[ len ];
142+
double *a;
143+
double *b;
136144
double t;
137145
int i;
138146

147+
a = (double *)malloc( len * sizeof( double ) );
148+
b = (double *)malloc( len * sizeof( double ) );
149+
if ( a == NULL || b == NULL ) {
150+
printf( "Error: failed to allocate memory\n" );
151+
return -1.0;
152+
}
139153
for ( i = 0; i < len; i++ ) {
140154
a[ i ] = ( rand_double() * 200.0 ) - 100.0;
141155
b[ i ] = ( rand_double() * 200.0 ) - 100.0;
@@ -152,6 +166,8 @@ static double benchmark2( int iterations, int len ) {
152166
if ( out[ 0 ] != out[ 0 ] ) {
153167
printf( "should not return NaN\n" );
154168
}
169+
free( a );
170+
free( b );
155171
return elapsed;
156172
}
157173

@@ -178,13 +194,21 @@ int main( void ) {
178194
count += 1;
179195
printf( "# c::%s:len=%d\n", NAME, len );
180196
elapsed = benchmark1( iter, len );
197+
if ( elapsed < 0.0 ) {
198+
printf( "not ok %d benchmark failed\n", count );
199+
continue;
200+
}
181201
print_results( iter, elapsed );
182202
printf( "ok %d benchmark finished\n", count );
183203
}
184204
for ( j = 0; j < REPEATS; j++ ) {
185205
count += 1;
186206
printf( "# c::%s:assign:len=%d\n", NAME, len );
187207
elapsed = benchmark2( iter, len );
208+
if ( elapsed < 0.0 ) {
209+
printf( "not ok %d benchmark failed\n", count );
210+
continue;
211+
}
188212
print_results( iter, elapsed );
189213
printf( "ok %d benchmark finished\n", count );
190214
}

0 commit comments

Comments
 (0)