Skip to content

Commit 57576bc

Browse files
bench: refactor to use dynamic memory allocation in blas/ext/base/dnancusumkbn
Replace Static Memory Allocation with Dynamic Memory Allocation --- 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: passed - 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 5e1d5be commit 57576bc

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

lib/node_modules/@stdlib/blas/ext/base/dnancusumkbn/benchmark/c/benchmark.length.c

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

104+
105+
x = (double *)malloc(len * sizeof(double));
106+
y = (double *)malloc(len * sizeof(double));
104107
for ( i = 0; i < len; i++ ) {
105108
if ( rand_double() < 0.2 ) {
106109
x[ i ] = 0.0 / 0.0; // NaN
@@ -122,23 +125,27 @@ static double benchmark1( int iterations, int len ) {
122125
if ( y[ len-1 ] != y[ len-1 ] ) {
123126
printf( "should not return NaN\n" );
124127
}
128+
free(x);
129+
free(y);
125130
return elapsed;
126131
}
127132

128133
/**
129-
* Runs a benchmark.
130-
*
131-
* @param iterations number of iterations
132-
* @param len array length
133-
* @return elapsed time in seconds
134-
*/
134+
* Runs a benchmark.
135+
*
136+
* @param iterations number of iterations
137+
* @param len array length
138+
* @return elapsed time in seconds
139+
*/
135140
static double benchmark2( int iterations, int len ) {
136141
double elapsed;
137-
double x[ len ];
138-
double y[ len ];
142+
double *x;
143+
double *y;
139144
double t;
140145
int i;
141146

147+
x = (double *)malloc(len * sizeof(double));
148+
y = (double *)malloc(len * sizeof(double));
142149
for ( i = 0; i < len; i++ ) {
143150
if ( rand_double() < 0.2 ) {
144151
x[ i ] = 0.0 / 0.0; // NaN
@@ -160,12 +167,14 @@ static double benchmark2( int iterations, int len ) {
160167
if ( y[ len-1 ] != y[ len-1 ] ) {
161168
printf( "should not return NaN\n" );
162169
}
170+
free(x);
171+
free(y);
163172
return elapsed;
164173
}
165174

166175
/**
167-
* Main execution sequence.
168-
*/
176+
* Main execution sequence.
177+
*/
169178
int main( void ) {
170179
double elapsed;
171180
int count;

0 commit comments

Comments
 (0)