Skip to content

Commit 2c13316

Browse files
bench: update random value generation
PR-URL: #6037 Reviewed-by: Athan Reines <[email protected]>
1 parent ef1d278 commit 2c13316

File tree

17 files changed

+128
-97
lines changed

17 files changed

+128
-97
lines changed

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

Lines changed: 6 additions & 5 deletions
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 isArray = require( '@stdlib/assert/is-array' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pkg = require( './../package.json' ).name;
@@ -35,10 +35,11 @@ bench( pkg, function benchmark( b ) {
3535
var y;
3636
var i;
3737

38+
x = uniform( 100, -50.0, 50.0 );
39+
3840
b.tic();
3941
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu() * 100.0 ) - 50.0;
41-
y = sici( x );
42+
y = sici( x[ i%x.length ] );
4243
if ( isnan( y[ 0 ] ) ) {
4344
b.fail( 'should not return NaN' );
4445
}
@@ -61,11 +62,11 @@ bench( pkg+':assign', function benchmark( b ) {
6162
var i;
6263

6364
out = [ 0.0, 0.0 ];
65+
x = uniform( 100, -50.0, 50.0 );
6466

6567
b.tic();
6668
for ( i = 0; i < b.iterations; i++ ) {
67-
x = ( randu() * 100.0 ) - 50.0;
68-
y = sici.assign( x, out, 1, 0 );
69+
y = sici.assign( x[ i%x.length ], out, 1, 0 );
6970
if ( isnan( y[ 0 ] ) ) {
7071
b.fail( 'should not return NaN' );
7172
}

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

Lines changed: 6 additions & 3 deletions
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 ] = ( 100.0*rand_double() ) - 50.0;
106+
}
107+
104108
t = tic();
105109
for ( i = 0; i < ITERATIONS; i++ ) {
106-
x = ( 100.0*rand_double() ) - 50.0;
107-
sici( x, &y, &z );
110+
sici( x[ i%100 ], &y, &z );
108111
if ( y != y || z != z ) {
109112
printf( "should not return NaN\n" );
110113
break;

lib/node_modules/@stdlib/math/base/special/sici/test/test.assign.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ tape( 'the function returns `[0,-Infinity]` if provided `0`', function test( t )
267267
out = [ 0.0, 0.0 ];
268268
val = sici( 0.0, out, 1, 0 );
269269
t.equal( val, out, 'returns output array' );
270-
t.strictEqual( val[ 0 ], 0.0, 'first element equals NaN' );
271-
t.strictEqual( val[ 1 ], NINF, 'second element equals -Infinity' );
270+
t.strictEqual( val[ 0 ], 0.0, 'returns expected value' );
271+
t.strictEqual( val[ 1 ], NINF, 'returns expected value' );
272272
t.end();
273273
});
274274

@@ -279,8 +279,8 @@ tape( 'the function returns `[-PI/2,NaN]` if provided `-Infinity`', function tes
279279
out = [ 0.0, 0.0 ];
280280
val = sici( NINF, out, 1, 0 );
281281
t.equal( val, out, 'returns output array' );
282-
t.strictEqual( val[ 0 ], -HALF_PI, 'first element equals -PI/2' );
283-
t.strictEqual( isnan( val[ 1 ] ), true, 'second element equals NaN' );
282+
t.strictEqual( val[ 0 ], -HALF_PI, 'returns expected value' );
283+
t.strictEqual( isnan( val[ 1 ] ), true, 'returns expected value' );
284284
t.end();
285285
});
286286

@@ -291,8 +291,8 @@ tape( 'the function returns `[PI/2,0]` if provided `+Infinity`', function test(
291291
out = [ 0.0, 0.0 ];
292292
val = sici( PINF, out, 1, 0 );
293293
t.equal( val, out, 'returns output array' );
294-
t.strictEqual( val[ 0 ], HALF_PI, 'first element equals PI/2' );
295-
t.strictEqual( val[ 1 ], 0, 'second element equals 0' );
294+
t.strictEqual( val[ 0 ], HALF_PI, 'returns expected value' );
295+
t.strictEqual( val[ 1 ], 0, 'returns expected value' );
296296
t.end();
297297
});
298298

@@ -303,8 +303,8 @@ tape( 'the function returns `[NaN,NaN]` if provided `NaN`', function test( t ) {
303303
out = [ 0.0, 0.0 ];
304304
val = sici( NaN, out, 1, 0 );
305305
t.equal( val, out, 'returns output array' );
306-
t.strictEqual( isnan( val[ 0 ] ), true, 'first element equals NaN' );
307-
t.strictEqual( isnan( val[ 1 ] ), true, 'second element equals NaN' );
306+
t.strictEqual( isnan( val[ 0 ] ), true, 'returns expected value' );
307+
t.strictEqual( isnan( val[ 1 ] ), true, 'returns expected value' );
308308
t.end();
309309
});
310310

@@ -316,8 +316,8 @@ tape( 'the function supports providing an output object (array)', function test(
316316
val = sici( 3.0, out, 1, 0 );
317317

318318
t.strictEqual( val, out, 'returns output object' );
319-
t.strictEqual( val[ 0 ], 1.848652527999468, 'has expected first element' );
320-
t.strictEqual( val[ 1 ], 0.11962978600800023, 'has expected second element' );
319+
t.strictEqual( val[ 0 ], 1.848652527999468, 'returns expected value' );
320+
t.strictEqual( val[ 1 ], 0.11962978600800023, 'returns expected value' );
321321

322322
t.end();
323323
});
@@ -330,8 +330,8 @@ tape( 'the function supports providing an output object (typed array)', function
330330
val = sici( 3.0, out, 1, 0 );
331331

332332
t.strictEqual( val, out, 'returns output object' );
333-
t.strictEqual( val[ 0 ], 1.848652527999468, 'has expected first element' );
334-
t.strictEqual( val[ 1 ], 0.11962978600800023, 'has expected second element' );
333+
t.strictEqual( val[ 0 ], 1.848652527999468, 'returns expected value' );
334+
t.strictEqual( val[ 1 ], 0.11962978600800023, 'returns expected value' );
335335

336336
t.end();
337337
});

lib/node_modules/@stdlib/math/base/special/sici/test/test.main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,31 +242,31 @@ tape( 'the function computes the sine and cosine integrals for very large positi
242242
tape( 'the function returns `[0,-Infinity]` if provided `0`', function test( t ) {
243243
var val = sici( 0.0 );
244244
t.strictEqual( isArray( val ), true, 'returns an array' );
245-
t.strictEqual( val[ 0 ], 0.0, 'first element equals NaN' );
246-
t.strictEqual( val[ 1 ], NINF, 'second element equals -Infinity' );
245+
t.strictEqual( val[ 0 ], 0.0, 'returns expected value' );
246+
t.strictEqual( val[ 1 ], NINF, 'returns expected value' );
247247
t.end();
248248
});
249249

250250
tape( 'the function returns `[-PI/2,NaN]` if provided `-Infinity`', function test( t ) {
251251
var val = sici( NINF );
252252
t.strictEqual( isArray( val ), true, 'returns an array' );
253-
t.strictEqual( val[ 0 ], -HALF_PI, 'first element equals -PI/2' );
254-
t.strictEqual( isnan( val[ 1 ] ), true, 'second element equals NaN' );
253+
t.strictEqual( val[ 0 ], -HALF_PI, 'returns expected value' );
254+
t.strictEqual( isnan( val[ 1 ] ), true, 'returns expected value' );
255255
t.end();
256256
});
257257

258258
tape( 'the function returns `[PI/2,0]` if provided `+Infinity`', function test( t ) {
259259
var val = sici( PINF );
260260
t.strictEqual( isArray( val ), true, 'returns an array' );
261-
t.strictEqual( val[ 0 ], HALF_PI, 'first element equals PI/2' );
262-
t.strictEqual( val[ 1 ], 0, 'second element equals 0' );
261+
t.strictEqual( val[ 0 ], HALF_PI, 'returns expected value' );
262+
t.strictEqual( val[ 1 ], 0, 'returns expected value' );
263263
t.end();
264264
});
265265

266266
tape( 'the function returns `[NaN,NaN]` if provided `NaN`', function test( t ) {
267267
var val = sici( NaN );
268268
t.strictEqual( isArray( val ), true, 'returns an array' );
269-
t.strictEqual( isnan( val[ 0 ] ), true, 'first element equals NaN' );
270-
t.strictEqual( isnan( val[ 1 ] ), true, 'second element equals NaN' );
269+
t.strictEqual( isnan( val[ 0 ] ), true, 'returns expected value' );
270+
t.strictEqual( isnan( val[ 1 ] ), true, 'returns expected value' );
271271
t.end();
272272
});

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

Lines changed: 7 additions & 5 deletions
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 pkg = require( './../package.json' ).name;
2727
var signum = require( './../lib' );
@@ -41,10 +41,11 @@ bench( pkg, function benchmark( b ) {
4141
var y;
4242
var i;
4343

44+
x = uniform( 100, -500.0, 500.0 );
45+
4446
b.tic();
4547
for ( i = 0; i < b.iterations; i++ ) {
46-
x = ( randu()*1000.0 ) - 500.0;
47-
y = signum( x );
48+
y = signum( x[ i%x.length ] );
4849
if ( isnan( y ) ) {
4950
b.fail( 'should not return NaN' );
5051
}
@@ -62,10 +63,11 @@ bench( pkg+'::built-in', opts, function benchmark( b ) {
6263
var y;
6364
var i;
6465

66+
x = uniform( 100, -500.0, 500.0 );
67+
6568
b.tic();
6669
for ( i = 0; i < b.iterations; i++ ) {
67-
x = ( randu()*1000.0 ) - 500.0;
68-
y = Math.sign( x ); // eslint-disable-line stdlib/no-builtin-math
70+
y = Math.sign( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
6971
if ( isnan( y ) ) {
7072
b.fail( 'should not return NaN' );
7173
}

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

Lines changed: 4 additions & 3 deletions
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, -500.0, 500.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*1000.0 ) - 500.0;
49-
y = signum( x );
50+
y = signum( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ 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 t;
9696
int i;
9797

98+
for ( i = 0; i < 100; i++ ) {
99+
x[ i ] = ( 1000.0 * rand_double() ) - 500.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 1000.0 * rand_double() ) - 500.0;
101-
y = signbit( x );
104+
y = signbit( x[ i%100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,19 @@ static double rand_double( void ) {
9696
* @return elapsed time in seconds
9797
*/
9898
static double benchmark( void ) {
99+
double x[ 100 ];
99100
double elapsed;
100-
double x;
101101
double t;
102102
int y;
103103
int i;
104104

105+
for ( i = 0; i < 100; i++ ) {
106+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
107+
}
108+
105109
t = tic();
106110
for ( i = 0; i < ITERATIONS; i++ ) {
107-
x = ( 1000.0*rand_double() ) - 500.0;
108-
y = signbit( x );
111+
y = signbit( x[ i%100 ] );
109112
if ( y > 1 || y < -1 ) {
110113
printf( "should not return a number greater than 1\n" );
111114
break;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double y;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( rand_double()*1000.0 ) - 500.0;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( rand_double()*1000.0 ) - 500.0;
102-
y = stdlib_base_signum( x );
105+
y = stdlib_base_signum( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,38 @@ tape( 'main export is a function', function test( t ) {
4040

4141
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
4242
var sign = signum( NaN );
43-
t.equal( isnan( sign ), true, 'returns NaN' );
43+
t.equal( isnan( sign ), true, 'returns expected value' );
4444
t.end();
4545
});
4646

4747
tape( 'the function returns `-0` if provided `-0`', function test( t ) {
4848
var sign = signum( -0.0 );
49-
t.equal( isNegativeZero( sign ), true, 'returns -0' );
49+
t.equal( isNegativeZero( sign ), true, 'returns expected value' );
5050
t.end();
5151
});
5252

5353
tape( 'the function returns `0` if provided +0', function test( t ) {
5454
var sign;
5555

5656
sign = signum( 0.0 );
57-
t.equal( isPositiveZero( sign ), true, 'returns +0' );
57+
t.equal( isPositiveZero( sign ), true, 'returns expected value' );
5858

5959
sign = signum( +0.0 );
60-
t.equal( isPositiveZero( sign ), true, 'returns +0' );
60+
t.equal( isPositiveZero( sign ), true, 'returns expected value' );
6161

6262
t.end();
6363
});
6464

6565
tape( 'the function returns `-1` if provided a negative number', function test( t ) {
66-
t.equal( signum( -10.0 ), -1.0, 'signum(-10) => -1' );
67-
t.equal( signum( -PI ), -1.0, 'signum(-π) => -1' );
68-
t.equal( signum( NINF ), -1.0, 'signum(-infinity) => -1' );
66+
t.equal( signum( -10.0 ), -1.0, 'returns expected value' );
67+
t.equal( signum( -PI ), -1.0, 'returns expected value' );
68+
t.equal( signum( NINF ), -1.0, 'returns expected value' );
6969
t.end();
7070
});
7171

7272
tape( 'the function returns `+1` if provided a positive number', function test( t ) {
73-
t.equal( signum( 10.0 ), 1.0, 'signum(10) => 1' );
74-
t.equal( signum( PI ), 1.0, 'signum(π) => 1' );
75-
t.equal( signum( PINF ), 1.0, 'signum(infinity) => 1' );
73+
t.equal( signum( 10.0 ), 1.0, 'returns expected value' );
74+
t.equal( signum( PI ), 1.0, 'returns expected value' );
75+
t.equal( signum( PINF ), 1.0, 'returns expected value' );
7676
t.end();
7777
});

0 commit comments

Comments
 (0)