Skip to content

Commit fd64a11

Browse files
committed
chore: add ndarray 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 6f23e36 commit fd64a11

1 file changed

Lines changed: 56 additions & 2 deletions

File tree

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static float rand_float( void ) {
9595
* @param len array length
9696
* @return elapsed time in seconds
9797
*/
98-
static double benchmark( int iterations, int len ) {
98+
static double benchmark1( int iterations, int len ) {
9999
uint8_t *mask;
100100
double elapsed;
101101
float *x;
@@ -131,6 +131,49 @@ static double benchmark( int iterations, int len ) {
131131
return elapsed;
132132
}
133133

134+
/**
135+
* Runs a benchmark.
136+
*
137+
* @param iterations number of iterations
138+
* @param len array length
139+
* @return elapsed time in seconds
140+
*/
141+
static double benchmark2( int iterations, int len ) {
142+
uint8_t *mask;
143+
double elapsed;
144+
float *x;
145+
float v;
146+
double t;
147+
int i;
148+
149+
x = (float *)malloc( len * sizeof( float ) );
150+
mask = (uint8_t *)malloc( len * sizeof( uint8_t ) );
151+
for ( i = 0; i < len; i++ ) {
152+
if ( rand_float() < 0.2f ) {
153+
mask[ i ] = 1; // missing
154+
} else {
155+
mask[ i ] = 0;
156+
}
157+
x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f;
158+
}
159+
v = 0.0f;
160+
t = tic();
161+
for ( i = 0; i < iterations; i++ ) {
162+
v = stdlib_strided_snanmskmidrange_ndarray( len, x, 1, 0, mask, 1, 0 );
163+
if ( v != v ) {
164+
printf( "should not return NaN\n" );
165+
break;
166+
}
167+
}
168+
elapsed = tic() - t;
169+
if ( v != v ) {
170+
printf( "should not return NaN\n" );
171+
}
172+
free( x );
173+
free( mask );
174+
return elapsed;
175+
}
176+
134177
/**
135178
* Main execution sequence.
136179
*/
@@ -153,7 +196,18 @@ int main( void ) {
153196
for ( j = 0; j < REPEATS; j++ ) {
154197
count += 1;
155198
printf( "# c::%s:len=%d\n", NAME, len );
156-
elapsed = benchmark( iter, len );
199+
elapsed = benchmark1( iter, len );
200+
print_results( iter, elapsed );
201+
printf( "ok %d benchmark finished\n", count );
202+
}
203+
}
204+
for ( i = MIN; i <= MAX; i++ ) {
205+
len = pow( 10, i );
206+
iter = ITERATIONS / pow( 10, i-1 );
207+
for ( j = 0; j < REPEATS; j++ ) {
208+
count += 1;
209+
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
210+
elapsed = benchmark2( iter, len );
157211
print_results( iter, elapsed );
158212
printf( "ok %d benchmark finished\n", count );
159213
}

0 commit comments

Comments
 (0)