Skip to content

Commit 44445ab

Browse files
authored
bench: update random value generation
PR-URL: #6302 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 551a3e9 commit 44445ab

File tree

25 files changed

+150
-103
lines changed

25 files changed

+150
-103
lines changed

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

+7-5
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 cbrt = 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 = cbrt( x );
48+
y = cbrt( 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.cbrt( x ); // eslint-disable-line stdlib/no-builtin-math
70+
y = Math.cbrt( 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/cbrt/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, -500.0, 500.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( 1000.0*randu() ) - 500.0;
49-
y = cbrt( x );
50+
y = cbrt( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,18 @@ static double rand_double( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
double x;
93+
double x[ 100 ];
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 = cbrt( x );
104+
y = cbrt( x[ i%100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,18 @@ static double rand_double( void ) {
9595
*/
9696
static double benchmark( void ) {
9797
double elapsed;
98-
double x;
98+
double x[ 100 ];
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 100; i++ ) {
104+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
105+
}
106+
103107
t = tic();
104108
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = ( 1000.0*rand_double() ) - 500.0;
106-
y = cbrt( x );
109+
y = cbrt( x[ i%100 ] );
107110
if ( y != y ) {
108111
printf( "should not return NaN\n" );
109112
break;

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double x;
94+
double x[ 100 ];
9595
double y;
9696
double t;
9797
int i;
9898

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

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -383,30 +383,30 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', function t
383383

384384
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
385385
var v = cbrt( NaN );
386-
t.equal( isnan( v ), true, 'returns NaN' );
386+
t.equal( isnan( v ), true, 'returns expected value' );
387387
t.end();
388388
});
389389

390390
tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) {
391391
var v = cbrt( NINF );
392-
t.equal( v, NINF, 'returns -infinity' );
392+
t.equal( v, NINF, 'returns expected value' );
393393
t.end();
394394
});
395395

396396
tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) {
397397
var v = cbrt( PINF );
398-
t.equal( v, PINF, 'returns +infinity' );
398+
t.equal( v, PINF, 'returns expected value' );
399399
t.end();
400400
});
401401

402402
tape( 'the function returns `+0` if provided `+0`', function test( t ) {
403403
var v = cbrt( +0.0 );
404-
t.equal( isPositiveZero( v ), true, 'returns 0' );
404+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
405405
t.end();
406406
});
407407

408408
tape( 'the function returns `-0` if provided `-0`', function test( t ) {
409409
var v = cbrt( -0.0 );
410-
t.equal( isNegativeZero( v ), true, 'returns -0' );
410+
t.equal( isNegativeZero( v ), true, 'returns expected value' );
411411
t.end();
412412
});

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -392,30 +392,30 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', opts, func
392392

393393
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
394394
var v = cbrt( NaN );
395-
t.equal( isnan( v ), true, 'returns NaN' );
395+
t.equal( isnan( v ), true, 'returns expected value' );
396396
t.end();
397397
});
398398

399399
tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) {
400400
var v = cbrt( NINF );
401-
t.equal( v, NINF, 'returns -infinity' );
401+
t.equal( v, NINF, 'returns expected value' );
402402
t.end();
403403
});
404404

405405
tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) {
406406
var v = cbrt( PINF );
407-
t.equal( v, PINF, 'returns +infinity' );
407+
t.equal( v, PINF, 'returns expected value' );
408408
t.end();
409409
});
410410

411411
tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) {
412412
var v = cbrt( +0.0 );
413-
t.equal( isPositiveZero( v ), true, 'returns 0' );
413+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
414414
t.end();
415415
});
416416

417417
tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) {
418418
var v = cbrt( -0.0 );
419-
t.equal( isNegativeZero( v ), true, 'returns -0' );
419+
t.equal( isNegativeZero( v ), true, 'returns expected value' );
420420
t.end();
421421
});

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

+11-5
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var cbrtf = require( './../lib' );
@@ -41,10 +41,13 @@ bench( pkg, function benchmark( b ) {
4141
var y;
4242
var i;
4343

44+
x = uniform( 100, -500.0, 500.0, {
45+
'dtype': 'float32'
46+
});
47+
4448
b.tic();
4549
for ( i = 0; i < b.iterations; i++ ) {
46-
x = ( randu()*1000.0 ) - 500.0;
47-
y = cbrtf( x );
50+
y = cbrtf( x[ i%x.length ] );
4851
if ( isnanf( y ) ) {
4952
b.fail( 'should not return NaN' );
5053
}
@@ -62,10 +65,13 @@ bench( pkg+'::built-in', opts, function benchmark( b ) {
6265
var y;
6366
var i;
6467

68+
x = uniform( 100, -500.0, 500.0, {
69+
'dtype': 'float32'
70+
});
71+
6572
b.tic();
6673
for ( i = 0; i < b.iterations; i++ ) {
67-
x = ( randu()*1000.0 ) - 500.0;
68-
y = Math.cbrt( x ); // eslint-disable-line stdlib/no-builtin-math
74+
y = Math.cbrt( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
6975
if ( isnanf( y ) ) {
7076
b.fail( 'should not return NaN' );
7177
}

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

+6-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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = uniform( 100, -500.0, 500.0, {
47+
'dtype': 'float32'
48+
});
49+
4650
b.tic();
4751
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( 1000.0*randu() ) - 500.0;
49-
y = cbrtf( x );
52+
y = cbrtf( x[ i%x.length ] );
5053
if ( isnanf( y ) ) {
5154
b.fail( 'should not return NaN' );
5255
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,18 @@ static float rand_float( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
float x;
93+
float x[ 100 ];
9494
float y;
9595
double t;
9696
int i;
9797

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

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ static float rand_float( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
float x;
94+
float x[ 100 ];
9595
float y;
9696
double t;
9797
int i;
9898

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

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -383,30 +383,30 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', function t
383383

384384
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
385385
var v = cbrtf( NaN );
386-
t.equal( isnanf( v ), true, 'returns NaN' );
386+
t.equal( isnanf( v ), true, 'returns expected value' );
387387
t.end();
388388
});
389389

390390
tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) {
391391
var v = cbrtf( NINF );
392-
t.equal( v, NINF, 'returns -infinity' );
392+
t.equal( v, NINF, 'returns expected value' );
393393
t.end();
394394
});
395395

396396
tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) {
397397
var v = cbrtf( PINF );
398-
t.equal( v, PINF, 'returns +infinity' );
398+
t.equal( v, PINF, 'returns expected value' );
399399
t.end();
400400
});
401401

402402
tape( 'the function returns `+0` if provided `+0`', function test( t ) {
403403
var v = cbrtf( +0.0 );
404-
t.equal( isPositiveZerof( v ), true, 'returns 0' );
404+
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
405405
t.end();
406406
});
407407

408408
tape( 'the function returns `-0` if provided `-0`', function test( t ) {
409409
var v = cbrtf( -0.0 );
410-
t.equal( isNegativeZerof( v ), true, 'returns -0' );
410+
t.equal( isNegativeZerof( v ), true, 'returns expected value' );
411411
t.end();
412412
});

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -392,30 +392,30 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', opts, func
392392

393393
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
394394
var v = cbrtf( NaN );
395-
t.equal( isnanf( v ), true, 'returns NaN' );
395+
t.equal( isnanf( v ), true, 'returns expected value' );
396396
t.end();
397397
});
398398

399399
tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) {
400400
var v = cbrtf( NINF );
401-
t.equal( v, NINF, 'returns -infinity' );
401+
t.equal( v, NINF, 'returns expected value' );
402402
t.end();
403403
});
404404

405405
tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) {
406406
var v = cbrtf( PINF );
407-
t.equal( v, PINF, 'returns +infinity' );
407+
t.equal( v, PINF, 'returns expected value' );
408408
t.end();
409409
});
410410

411411
tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) {
412412
var v = cbrtf( +0.0 );
413-
t.equal( isPositiveZerof( v ), true, 'returns 0' );
413+
t.equal( isPositiveZerof( v ), true, 'returns expected value' );
414414
t.end();
415415
});
416416

417417
tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) {
418418
var v = cbrtf( -0.0 );
419-
t.equal( isNegativeZerof( v ), true, 'returns -0' );
419+
t.equal( isNegativeZerof( v ), true, 'returns expected value' );
420420
t.end();
421421
});

0 commit comments

Comments
 (0)