Skip to content

Commit c74e75b

Browse files
bench: refactor random generation
--- 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: passed - 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 ---
1 parent d9c2e28 commit c74e75b

File tree

8 files changed

+44
-32
lines changed

8 files changed

+44
-32
lines changed

lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,22 @@ static double rand_double( void ) {
8989
* @return elapsed time in seconds
9090
*/
9191
static double benchmark( void ) {
92+
double re[ 100 ];
93+
double im[ 100 ];
9294
double complex z;
9395
double elapsed;
94-
double re;
95-
double im;
9696
double y;
9797
double t;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
re[ i ] = ( 1000.0*rand_double() ) - 500.0;
102+
im[ i ] = ( 1000.0*rand_double() ) - 500.0;
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
re = ( 1000.0*rand_double() ) - 500.0;
103-
im = ( 1000.0*rand_double() ) - 500.0;
104-
z = re + im*I;
107+
z = re[ i%100 ] + im[ i%100 ]*I;
105108
y = cabs( z );
106109
if ( y != y ) {
107110
printf( "should not return NaN\n" );

lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,23 @@ static double rand_double( void ) {
9292
* @return elapsed time in seconds
9393
*/
9494
static double benchmark( void ) {
95+
double re[ 100 ];
96+
double im[ 100 ];
9597
double elapsed;
96-
double re;
97-
double im;
9898
double y;
9999
double t;
100100
int i;
101101

102+
for ( i = 0; i < 100; i++ ) {
103+
re[ i ] = ( 1000.0*rand_double() ) - 500.0;
104+
im[ i ] = ( 1000.0*rand_double() ) - 500.0;
105+
}
106+
102107
stdlib_complex128_t z;
103108

104109
t = tic();
105110
for ( i = 0; i < ITERATIONS; i++ ) {
106-
re = ( 1000.0*rand_double() ) - 500.0;
107-
im = ( 1000.0*rand_double() ) - 500.0;
108-
z = stdlib_complex128( re, im );
111+
z = stdlib_complex128( re[ i % 100 ], im[ i % 100 ] );
109112
y = stdlib_base_cabs( z );
110113
if ( y != y ) {
111114
printf( "should not return NaN\n" );

lib/node_modules/@stdlib/math/base/special/cabs/test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns
7171
var v;
7272

7373
v = cabs( new Complex128( NaN, 3.0 ) );
74-
t.strictEqual( isnan( v ), true, 'returns NaN' );
74+
t.strictEqual( isnan( v ), true, 'returns expected value' );
7575

7676
v = cabs( new Complex128( 5.0, NaN ) );
77-
t.strictEqual( isnan( v ), true, 'returns NaN' );
77+
t.strictEqual( isnan( v ), true, 'returns expected value' );
7878

7979
v = cabs( new Complex128( NaN, NaN ) );
80-
t.strictEqual( isnan( v ), true, 'returns NaN' );
80+
t.strictEqual( isnan( v ), true, 'returns expected value' );
8181

8282
t.end();
8383
});

lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns
8080
var v;
8181

8282
v = cabs( new Complex128( NaN, 3.0 ) );
83-
t.strictEqual( isnan( v ), true, 'returns NaN' );
83+
t.strictEqual( isnan( v ), true, 'returns expected value' );
8484

8585
v = cabs( new Complex128( 5.0, NaN ) );
86-
t.strictEqual( isnan( v ), true, 'returns NaN' );
86+
t.strictEqual( isnan( v ), true, 'returns expected value' );
8787

8888
v = cabs( new Complex128( NaN, NaN ) );
89-
t.strictEqual( isnan( v ), true, 'returns NaN' );
89+
t.strictEqual( isnan( v ), true, 'returns expected value' );
9090

9191
t.end();
9292
});

lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,22 @@ double cabs2( double complex z ) {
9999
* @return elapsed time in seconds
100100
*/
101101
static double benchmark( void ) {
102+
double re[ 100 ];
103+
double im[ 100 ];
102104
double complex z;
103105
double elapsed;
104-
double re;
105-
double im;
106106
double y;
107107
double t;
108108
int i;
109109

110+
for ( i = 0; i < 100; i++ ) {
111+
re[ i ] = ( 1000.0*rand_double() ) - 500.0;
112+
im[ i ] = ( 1000.0*rand_double() ) - 500.0;
113+
}
114+
110115
t = tic();
111116
for ( i = 0; i < ITERATIONS; i++ ) {
112-
re = ( 1000.0*rand_double() ) - 500.0;
113-
im = ( 1000.0*rand_double() ) - 500.0;
114-
z = re + im*I;
117+
z = re[ i%100] + im[ i%100 ]*I;
115118
y = cabs2( z );
116119
if ( y != y ) {
117120
printf( "should not return NaN\n" );

lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,23 @@ static double rand_double( void ) {
9292
* @return elapsed time in seconds
9393
*/
9494
static double benchmark( void ) {
95+
double re[ 100 ];
96+
double im[ 100 ];
9597
double elapsed;
96-
double re;
97-
double im;
9898
double y;
9999
double t;
100100
int i;
101101

102+
for ( i = 0; i < 100; i++ ) {
103+
re[ i ] = ( 1000.0*rand_double() ) - 500.0;
104+
im[ i ] = ( 1000.0*rand_double() ) - 500.0;
105+
}
106+
102107
stdlib_complex128_t z;
103108

104109
t = tic();
105110
for ( i = 0; i < ITERATIONS; i++ ) {
106-
re = ( 1000.0*rand_double() ) - 500.0;
107-
im = ( 1000.0*rand_double() ) - 500.0;
108-
z = stdlib_complex128( re, im );
111+
z = stdlib_complex128( re[ i % 100 ], im[ i % 100 ] );
109112
y = stdlib_base_cabs2( z );
110113
if ( y != y ) {
111114
printf( "should not return NaN\n" );

lib/node_modules/@stdlib/math/base/special/cabs2/test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns
7171
var v;
7272

7373
v = cabs2( new Complex128( NaN, 3.0 ) );
74-
t.strictEqual( isnan( v ), true, 'returns NaN' );
74+
t.strictEqual( isnan( v ), true, 'returns expected value' );
7575

7676
v = cabs2( new Complex128( 5.0, NaN ) );
77-
t.strictEqual( isnan( v ), true, 'returns NaN' );
77+
t.strictEqual( isnan( v ), true, 'returns expected value' );
7878

7979
v = cabs2( new Complex128( NaN, NaN ) );
80-
t.strictEqual( isnan( v ), true, 'returns NaN' );
80+
t.strictEqual( isnan( v ), true, 'returns expected value' );
8181

8282
t.end();
8383
});

lib/node_modules/@stdlib/math/base/special/cabs2/test/test.native.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns
8080
var v;
8181

8282
v = cabs2( new Complex128( NaN, 3.0 ) );
83-
t.strictEqual( isnan( v ), true, 'returns NaN' );
83+
t.strictEqual( isnan( v ), true, 'returns expected value' );
8484

8585
v = cabs2( new Complex128( 5.0, NaN ) );
86-
t.strictEqual( isnan( v ), true, 'returns NaN' );
86+
t.strictEqual( isnan( v ), true, 'returns expected value' );
8787

8888
v = cabs2( new Complex128( NaN, NaN ) );
89-
t.strictEqual( isnan( v ), true, 'returns NaN' );
89+
t.strictEqual( isnan( v ), true, 'returns expected value' );
9090

9191
t.end();
9292
});

0 commit comments

Comments
 (0)