Skip to content

Commit e70e956

Browse files
bench: refactor to use dynamic memory allocation in stats/strided/dmin
--- 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 153933e commit e70e956

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/node_modules/@stdlib/stats/strided/dmin/benchmark/c/benchmark.length.c

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

104+
x = (double *) malloc( len * sizeof( double ) );
104105
for ( i = 0; i < len; i++ ) {
105106
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
106107
}
@@ -118,6 +119,7 @@ static double benchmark1( int iterations, int len ) {
118119
if ( v != v ) {
119120
printf( "should not return NaN\n" );
120121
}
122+
free( x );
121123
return elapsed;
122124
}
123125

@@ -130,11 +132,12 @@ static double benchmark1( int iterations, int len ) {
130132
*/
131133
static double benchmark2( int iterations, int len ) {
132134
double elapsed;
133-
double x[ len ];
135+
double *x;
134136
double v;
135137
double t;
136138
int i;
137139

140+
x = (double *) malloc( len * sizeof( double ) );
138141
for ( i = 0; i < len; i++ ) {
139142
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
140143
}
@@ -152,6 +155,7 @@ static double benchmark2( int iterations, int len ) {
152155
if ( v != v ) {
153156
printf( "should not return NaN\n" );
154157
}
158+
free( x );
155159
return elapsed;
156160
}
157161

0 commit comments

Comments
 (0)