Skip to content

Commit 6825214

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: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent bc85b9a commit 6825214

File tree

2 files changed

+47
-48
lines changed

2 files changed

+47
-48
lines changed

lib/node_modules/@stdlib/blas/base/srotg/benchmark/c/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2025 The Stdlib Authors.
4+
# Copyright (c) 2024 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.
@@ -82,7 +82,7 @@ LIBRARIES ?=
8282
LIBPATH ?=
8383

8484
# List of C targets:
85-
c_targets := benchmark.out
85+
c_targets := benchmark.length.out
8686

8787

8888
# RULES #

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

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2024 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.
@@ -17,17 +17,17 @@
1717
*/
1818

1919
#include "stdlib/blas/base/srotg.h"
20-
#include "stdlib/math/base/assert/is_nan.h"
21-
#include "stdlib/constants/float64/eps.h"
2220
#include <stdlib.h>
2321
#include <stdio.h>
2422
#include <math.h>
2523
#include <time.h>
2624
#include <sys/time.h>
2725

2826
#define NAME "srotg"
29-
#define ITERATIONS 1000000
27+
#define ITERATIONS 10000000
3028
#define REPEATS 3
29+
#define MIN 1
30+
#define MAX 6
3131

3232
/**
3333
* Prints the TAP version.
@@ -39,7 +39,7 @@ static void print_version( void ) {
3939
/**
4040
* Prints the TAP summary.
4141
*
42-
* @param total total number of tests
42+
* @param total total number of tests
4343
* @param passing total number of passing tests
4444
*/
4545
static void print_summary( int total, int passing ) {
@@ -54,12 +54,13 @@ static void print_summary( int total, int passing ) {
5454
/**
5555
* Prints benchmarks results.
5656
*
57-
* @param elapsed elapsed time in seconds
57+
* @param iterations number of iterations
58+
* @param elapsed elapsed time in seconds
5859
*/
59-
static void print_results( double elapsed ) {
60-
double rate = (double)ITERATIONS / elapsed;
60+
static void print_results( int iterations, double elapsed ) {
61+
double rate = (double)iterations / elapsed;
6162
printf( " ---\n" );
62-
printf( " iterations: %d\n", ITERATIONS );
63+
printf( " iterations: %d\n", iterations );
6364
printf( " elapsed: %0.9f\n", elapsed );
6465
printf( " rate: %0.9f\n", rate );
6566
printf( " ...\n" );
@@ -77,46 +78,45 @@ static double tic( void ) {
7778
}
7879

7980
/**
80-
* Generates a random number on the interval [min,max).
81+
* Generates a random number on the interval [0,1).
8182
*
82-
* @param min minimum value (inclusive)
83-
* @param max maximum value (exclusive)
84-
* @return random number
83+
* @return random number
8584
*/
86-
static double random_uniform( const double min, const double max ) {
87-
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
88-
return min + ( v*(max-min) );
85+
static float rand_float( void ) {
86+
int r = rand();
87+
return (float)r / ( (float)RAND_MAX + 1.0 );
8988
}
9089

9190
/**
9291
* Runs a benchmark.
9392
*
94-
* @return elapsed time in seconds
93+
* @param iterations number of iterations
94+
* @param len array length
95+
* @return elapsed time in seconds
9596
*/
96-
static double benchmark1( void ) {
97+
static double benchmark1( int iterations, int len ) {
9798
double elapsed;
98-
float a[ 100 ];
99-
float b[ 100 ];
100-
float Out[ 4 ];
99+
float a[ len ];
100+
float b[ len ];
101+
float Out[4];
101102
double t;
102103
int i;
103104

104-
for ( i = 0; i < 100; i++ ) {
105-
a[ i ] = random_uniform( 0.0, 100.0 );
106-
b[ i ] = random_uniform( 0.0, 100.0 ) - 50.0;
105+
for ( i = 0; i < len; i++ ) {
106+
a[ i ] = ( rand_float()*200.0f ) - 100.0f;
107+
b[ i ] = ( rand_float()*200.0f ) - 100.0f;
107108
}
108109

109110
t = tic();
110-
for ( i = 0; i < ITERATIONS; i++ ) {
111-
// cppcheck-suppress uninitvar
112-
c_srotg( a[ i % 100 ], b[ i % 100 ], Out, 1 );
113-
if ( stdlib_base_is_nan( Out[0] ) || stdlib_base_is_nan( Out[1] ) || stdlib_base_is_nan( Out[2] ) || stdlib_base_is_nan( Out[3] ) ) {
111+
for ( i = 0; i < iterations; i++ ) {
112+
c_srotg( a[i % len ], b[i % len ], Out, 1 );
113+
if ( Out[ 0 ] != Out[ 0 ] ) {
114114
printf( "should not return NaN\n" );
115115
break;
116116
}
117117
}
118118
elapsed = tic() - t;
119-
if ( stdlib_base_is_nan( Out[0] ) || stdlib_base_is_nan( Out[1] ) || stdlib_base_is_nan( Out[2] ) || stdlib_base_is_nan( Out[3] ) ) {
119+
if ( Out[ 0 ] != Out[ 0 ] ) {
120120
printf( "should not return NaN\n" );
121121
}
122122
return elapsed;
@@ -125,32 +125,33 @@ static double benchmark1( void ) {
125125
/**
126126
* Runs a benchmark.
127127
*
128-
* @return elapsed time in seconds
128+
* @param iterations number of iterations
129+
* @param len array length
130+
* @return elapsed time in seconds
129131
*/
130-
static double benchmark2( void ) {
132+
static double benchmark2( int iterations, int len ) {
131133
double elapsed;
132-
float a[ 100 ];
133-
float b[ 100 ];
134-
float Out[ 4 ];
134+
float a[ len ];
135+
float b[ len ];
136+
float Out[4];
135137
double t;
136138
int i;
137139

138-
for ( i = 0; i < 100; i++ ) {
139-
a[ i ] = random_uniform( 0.0, 100.0 );
140-
b[ i ] = random_uniform( 0.0, 100.0 ) - 50.0;
140+
for ( i = 0; i < len; i++ ) {
141+
a[ i ] = ( rand_float()*200.0f ) - 100.0f;
142+
b[ i ] = ( rand_float()*200.0f ) - 100.0f;
141143
}
142144

143145
t = tic();
144-
for ( i = 0; i < ITERATIONS; i++ ) {
145-
// cppcheck-suppress uninitvar
146-
c_srotg_assign( a[ i % 100 ], b[ i % 100 ], Out, 1, 0 );
147-
if ( stdlib_base_is_nan( Out[0] ) || stdlib_base_is_nan( Out[1] ) || stdlib_base_is_nan( Out[2] ) || stdlib_base_is_nan( Out[3] ) ) {
146+
for ( i = 0; i < iterations; i++ ) {
147+
c_srotg_assign( a[i % len ], b[i % len ], Out, 1, 0 );
148+
if ( Out[ 0 ] != Out[ 0 ] ) {
148149
printf( "should not return NaN\n" );
149150
break;
150151
}
151152
}
152153
elapsed = tic() - t;
153-
if ( stdlib_base_is_nan( Out[0] ) || stdlib_base_is_nan( Out[1] ) || stdlib_base_is_nan( Out[2] ) || stdlib_base_is_nan( Out[3] ) ) {
154+
if ( Out[ 0 ] != Out[ 0 ] ) {
154155
printf( "should not return NaN\n" );
155156
}
156157
return elapsed;
@@ -166,8 +167,10 @@ int main( void ) {
166167
int len;
167168
int i;
168169
int j;
170+
169171
// Use the current time to seed the random number generator:
170172
srand( time( NULL ) );
173+
171174
print_version();
172175
count = 0;
173176
for ( i = MIN; i <= MAX; i++ ) {
@@ -180,10 +183,6 @@ int main( void ) {
180183
print_results( iter, elapsed );
181184
printf( "ok %d benchmark finished\n", count );
182185
}
183-
}
184-
for ( i = MIN; i <= MAX; i++ ) {
185-
len = pow( 10, i );
186-
iter = ITERATIONS / pow( 10, i-1 );
187186
for ( j = 0; j < REPEATS; j++ ) {
188187
count += 1;
189188
printf( "# c::%s:ndarray:len=%d\n", NAME, len );

0 commit comments

Comments
 (0)