Skip to content

Commit e196811

Browse files
bench: update random value generation
PR-URL: #5987 Reviewed-by: Athan Reines <[email protected]>
1 parent fba8768 commit e196811

File tree

13 files changed

+116
-84
lines changed

13 files changed

+116
-84
lines changed

lib/node_modules/@stdlib/math/base/special/sincos/benchmark/benchmark.js

+21-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var sin = require( '@stdlib/math/base/special/sin' );
2727
var cos = require( '@stdlib/math/base/special/cos' );
@@ -36,10 +36,11 @@ bench( pkg, function benchmark( b ) {
3636
var y;
3737
var i;
3838

39+
x = uniform( 100, -10.0, 10.0 );
40+
3941
b.tic();
4042
for ( i = 0; i < b.iterations; i++ ) {
41-
x = ( randu()*20.0 ) - 10.0;
42-
y = sincos( x );
43+
y = sincos( x[ i%x.length ] );
4344
if ( isnan( y[0] ) || isnan( y[1] ) ) {
4445
b.fail( 'should not return NaN' );
4546
}
@@ -57,11 +58,12 @@ bench( pkg+'::separate-evaluation', function benchmark( b ) {
5758
var y;
5859
var i;
5960

61+
x = uniform( 100, -10.0, 10.0 );
6062
y = [ 0.0, 0.0 ];
63+
6164
b.tic();
6265
for ( i = 0; i < b.iterations; i++ ) {
63-
x = ( randu()*20.0 ) - 10.0;
64-
y = [ sin( x ), cos( x ) ];
66+
y = [ sin( x[ i%x.length ] ), cos( x[ i%x.length ] ) ];
6567
if ( isnan( y[0] ) || isnan( y[1] ) ) {
6668
b.fail( 'should not return NaN' );
6769
}
@@ -79,11 +81,12 @@ bench( pkg+':assign', function benchmark( b ) {
7981
var y;
8082
var i;
8183

84+
x = uniform( 100, -10.0, 10.0 );
8285
y = [ 0.0, 0.0 ];
86+
8387
b.tic();
8488
for ( i = 0; i < b.iterations; i++ ) {
85-
x = ( randu()*20.0 ) - 10.0;
86-
sincos.assign( x, y, 1, 0 );
89+
sincos.assign( x[ i%x.length ], y, 1, 0 );
8790
if ( isnan( y[0] ) || isnan( y[1] ) ) {
8891
b.fail( 'should not return NaN' );
8992
}
@@ -101,12 +104,13 @@ bench( pkg+'::separate-evaluation,in-place', function benchmark( b ) {
101104
var y;
102105
var i;
103106

107+
x = uniform( 100, -10.0, 10.0 );
104108
y = [ 0.0, 0.0 ];
109+
105110
b.tic();
106111
for ( i = 0; i < b.iterations; i++ ) {
107-
x = ( randu()*20.0 ) - 10.0;
108-
y[0] = sin( x );
109-
y[1] = cos( x );
112+
y[0] = sin( x[ i%x.length ] );
113+
y[1] = cos( x[ i%x.length ] );
110114
if ( isnan( y[0] ) || isnan( y[1] ) ) {
111115
b.fail( 'should not return NaN' );
112116
}
@@ -124,10 +128,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
124128
var y;
125129
var i;
126130

131+
x = uniform( 100, -10.0, 10.0 );
132+
127133
b.tic();
128134
for ( i = 0; i < b.iterations; i++ ) {
129-
x = ( randu()*20.0 ) - 10.0;
130-
y = [ Math.sin( x ), Math.cos( x ) ]; // eslint-disable-line stdlib/no-builtin-math
135+
y = [ Math.sin( x[ i%x.length ] ), Math.cos( x[ i%x.length ] ) ]; // eslint-disable-line stdlib/no-builtin-math
131136
if ( isnan( y[0] ) || isnan( y[1] ) ) {
132137
b.fail( 'should not return NaN' );
133138
}
@@ -145,12 +150,13 @@ bench( pkg+'::built-in,in-place', function benchmark( b ) {
145150
var y;
146151
var i;
147152

153+
x = uniform( 100, -10.0, 10.0 );
148154
y = [ 0.0, 0.0 ];
155+
149156
b.tic();
150157
for ( i = 0; i < b.iterations; i++ ) {
151-
x = ( randu()*20.0 ) - 10.0;
152-
y[0] = Math.sin( x ); // eslint-disable-line stdlib/no-builtin-math
153-
y[1] = Math.cos( x ); // eslint-disable-line stdlib/no-builtin-math
158+
y[0] = Math.sin( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
159+
y[1] = Math.cos( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
154160
if ( isnan( y[0] ) || isnan( y[1] ) ) {
155161
b.fail( 'should not return NaN' );
156162
}

lib/node_modules/@stdlib/math/base/special/sincos/benchmark/benchmark.native.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = uniform( 100, -10.0, 10.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu() * 20.0 ) - 10.0;
49-
y = sincos( x );
50+
y = sincos( x[ i%x.length ] );
5051
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,21 @@ static double rand_double( void ) {
8989
* @return elapsed time in seconds
9090
*/
9191
static double benchmark( void ) {
92+
double x[ 100 ];
9293
double elapsed;
93-
double x;
9494
double y;
9595
double z;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 20.0 * rand_double() ) - 10.0;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 20.0 * rand_double() ) - 10.0;
102-
y = sin( x );
103-
z = cos( x );
105+
y = sin( x[ i%100 ] );
106+
z = cos( x[ i%100 ] );
104107
if ( y != y || z != z ) {
105108
printf( "should not return NaN\n" );
106109
break;

lib/node_modules/@stdlib/math/base/special/sincos/benchmark/c/cephes/benchmark.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,20 @@ static double rand_double( void ) {
9494
* @return elapsed time in seconds
9595
*/
9696
static double benchmark( void ) {
97+
double x[ 100 ];
9798
double elapsed;
98-
double x;
9999
double y;
100100
double z;
101101
double t;
102102
int i;
103103

104+
for ( i = 0; i < 100; i++ ) {
105+
x[ i ] = ( 20.0*rand_double() ) - 10.0;
106+
}
107+
104108
t = tic();
105109
for ( i = 0; i < ITERATIONS; i++ ) {
106-
x = ( 20.0*rand_double() ) - 10.0;
107-
sincos( x, &y, &z, 0 );
110+
sincos( x[ i%100 ], &y, &z, 0 );
108111
if ( y != y || z != z ) {
109112
printf( "should not return NaN\n" );
110113
break;

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,20 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
9495
double cosine;
9596
double sine;
96-
double x;
9797
double t;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 20.0 * rand_double() ) - 10.0;
102+
}
103+
100104
t = tic();
101105
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( 20.0 * rand_double() ) - 10.0;
103-
stdlib_base_sincos( x, &sine, &cosine );
106+
stdlib_base_sincos( x[ i%100 ], &sine, &cosine );
104107
if ( cosine != cosine || sine != sine ) {
105108
printf( "unexpected results\n" );
106109
break;

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,20 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
9495
double cosine;
9596
double sine;
96-
double x;
9797
double t;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 20.0 * rand_double() ) - 10.0;
102+
}
103+
100104
t = tic();
101105
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( 20.0 * rand_double() ) - 10.0;
103-
stdlib_base_sincosd( x, &sine, &cosine );
106+
stdlib_base_sincosd( x[ i%100 ], &sine, &cosine );
104107
if ( cosine != cosine || sine != sine ) {
105108
printf( "unexpected results\n" );
106109
break;

lib/node_modules/@stdlib/math/base/special/sincospi/benchmark/benchmark.js

+21-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var sinpi = require( '@stdlib/math/base/special/sinpi' );
2727
var cospi = require( '@stdlib/math/base/special/cospi' );
@@ -37,10 +37,11 @@ bench( pkg, function benchmark( b ) {
3737
var y;
3838
var i;
3939

40+
x = uniform( 100, -10.0, 10.0 );
41+
4042
b.tic();
4143
for ( i = 0; i < b.iterations; i++ ) {
42-
x = ( randu()*20.0 ) - 10.0;
43-
y = sincospi( x );
44+
y = sincospi( x[ i%x.length ] );
4445
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
4546
b.fail( 'should not return NaN' );
4647
}
@@ -58,11 +59,12 @@ bench( pkg+'::separate-evaluation', function benchmark( b ) {
5859
var y;
5960
var i;
6061

62+
x = uniform( 100, -10.0, 10.0 );
6163
y = [ 0.0, 0.0 ];
64+
6265
b.tic();
6366
for ( i = 0; i < b.iterations; i++ ) {
64-
x = ( randu()*20.0 ) - 10.0;
65-
y = [ sinpi( x ), cospi( x ) ];
67+
y = [ sinpi( x[ i%x.length ] ), cospi( x[ i%x.length ] ) ];
6668
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
6769
b.fail( 'should not return NaN' );
6870
}
@@ -80,11 +82,12 @@ bench( pkg+':assign', function benchmark( b ) {
8082
var y;
8183
var i;
8284

85+
x = uniform( 100, -10.0, 10.0 );
8386
y = [ 0.0, 0.0 ];
87+
8488
b.tic();
8589
for ( i = 0; i < b.iterations; i++ ) {
86-
x = ( randu()*20.0 ) - 10.0;
87-
sincospi.assign( x, y, 1, 0 );
90+
sincospi.assign( x[ i%x.length ], y, 1, 0 );
8891
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
8992
b.fail( 'should not return NaN' );
9093
}
@@ -102,12 +105,13 @@ bench( pkg+'::separate-evaluation,in-place', function benchmark( b ) {
102105
var y;
103106
var i;
104107

108+
x = uniform( 100, -10.0, 10.0 );
105109
y = [ 0.0, 0.0 ];
110+
106111
b.tic();
107112
for ( i = 0; i < b.iterations; i++ ) {
108-
x = ( randu()*20.0 ) - 10.0;
109-
y[ 0 ] = sinpi( x );
110-
y[ 1 ] = cospi( x );
113+
y[ 0 ] = sinpi( x[ i%x.length ] );
114+
y[ 1 ] = cospi( x[ i%x.length ] );
111115
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
112116
b.fail( 'should not return NaN' );
113117
}
@@ -125,10 +129,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
125129
var y;
126130
var i;
127131

132+
x = uniform( 100, -10.0, 10.0 );
133+
128134
b.tic();
129135
for ( i = 0; i < b.iterations; i++ ) {
130-
x = ( randu()*20.0 ) - 10.0;
131-
y = [ Math.sin( PI*x ), Math.cos( PI*x ) ]; // eslint-disable-line stdlib/no-builtin-math
136+
y = [ Math.sin( PI*x[ i%x.length ] ), Math.cos( PI*x[ i%x.length ] ) ]; // eslint-disable-line stdlib/no-builtin-math
132137
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
133138
b.fail( 'should not return NaN' );
134139
}
@@ -146,12 +151,13 @@ bench( pkg+'::built-in,in-place', function benchmark( b ) {
146151
var y;
147152
var i;
148153

154+
x = uniform( 100, -10.0, 10.0 );
149155
y = [ 0.0, 0.0 ];
156+
150157
b.tic();
151158
for ( i = 0; i < b.iterations; i++ ) {
152-
x = ( randu()*20.0 ) - 10.0;
153-
y[ 0 ] = Math.sin( PI*x ); // eslint-disable-line stdlib/no-builtin-math
154-
y[ 1 ] = Math.cos( PI*x ); // eslint-disable-line stdlib/no-builtin-math
159+
y[ 0 ] = Math.sin( PI*x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
160+
y[ 1 ] = Math.cos( PI*x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
155161
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
156162
b.fail( 'should not return NaN' );
157163
}

lib/node_modules/@stdlib/math/base/special/sincospi/benchmark/benchmark.native.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = uniform( 100, -10.0, 10.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu() * 20.0 ) - 10.0;
49-
y = sincospi( x );
50+
y = sincospi( x[ i%x.length ] );
5051
if ( isnan( y[ 0 ] ) || isnan( y[ 1 ] ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,21 @@ static double rand_double( void ) {
8989
* @return elapsed time in seconds
9090
*/
9191
static double benchmark( void ) {
92+
double x[ 100 ];
9293
double elapsed;
93-
double x;
9494
double y;
9595
double z;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 20.0 * rand_double() ) - 10.0;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 20.0 * rand_double() ) - 10.0;
102-
y = sin( M_PI * x );
103-
z = cos( M_PI * x );
105+
y = sin( M_PI * x[ i%100 ] );
106+
z = cos( M_PI * x[ i%100 ] );
104107
if ( y != y || z != z ) {
105108
printf( "should not return NaN\n" );
106109
break;

0 commit comments

Comments
 (0)