Skip to content

Commit 5924f84

Browse files
committed
bench: update random value generation
1 parent 3ef117f commit 5924f84

File tree

18 files changed

+91
-70
lines changed

18 files changed

+91
-70
lines changed

lib/node_modules/@stdlib/math/base/special/exp/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 exp = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = uniform( 100, -50.0, 50.0 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*100.0 ) - 50.0;
40-
y = exp( x );
41+
y = exp( x[ i%x.length ] );
4142
if ( isnan( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}
@@ -55,10 +56,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
5556
var y;
5657
var i;
5758

59+
x = uniform( 100, -50.0, 50.0 );
60+
5861
b.tic();
5962
for ( i = 0; i < b.iterations; i++ ) {
60-
x = ( randu()*100.0 ) - 50.0;
61-
y = Math.exp( x ); // eslint-disable-line stdlib/no-builtin-math
63+
y = Math.exp( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math
6264
if ( isnan( y ) ) {
6365
b.fail( 'should not return NaN' );
6466
}

lib/node_modules/@stdlib/math/base/special/exp/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.0 ) - 50.0;
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*100.0 ) - 50.0;
49-
y = exp( x );
50+
y = exp( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

Lines changed: 6 additions & 3 deletions
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 ] = ( 100.0*rand_double() ) - 50.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 100.0*rand_double() ) - 50.0;
101-
y = exp( x );
104+
y = exp( x[ i%100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

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

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

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

Lines changed: 6 additions & 3 deletions
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 ] = ( 100.0*rand_double() ) - 50.0;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 100.0*rand_double() ) - 50.0;
102-
y = stdlib_base_exp( x );
105+
y = stdlib_base_exp( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,18 @@ tape( 'the function accurately computes the natural exponential function for ver
148148

149149
tape( 'the function returns `0` if provided a `-infinity`', function test( t ) {
150150
var val = exp( NINF );
151-
t.equal( val, 0.0, 'returns 0' );
151+
t.equal( val, 0.0, 'returns expected value' );
152152
t.end();
153153
});
154154

155155
tape( 'the function returns `+infinity` if provided a `+infinity`', function test( t ) {
156156
var val = exp( PINF );
157-
t.equal( val, PINF, 'returns +infinity' );
157+
t.equal( val, PINF, 'returns expected value' );
158158
t.end();
159159
});
160160

161161
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
162162
var val = exp( NaN );
163-
t.equal( isnan( val ), true, 'returns NaN' );
163+
t.equal( isnan( val ), true, 'returns expected value' );
164164
t.end();
165165
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,18 @@ tape( 'the function accurately computes the natural exponential function for ver
157157

158158
tape( 'the function returns `0` if provided a `-infinity`', opts, function test( t ) {
159159
var val = exp( NINF );
160-
t.equal( val, 0.0, 'returns 0' );
160+
t.equal( val, 0.0, 'returns expected value' );
161161
t.end();
162162
});
163163

164164
tape( 'the function returns `+infinity` if provided a `+infinity`', opts, function test( t ) {
165165
var val = exp( PINF );
166-
t.equal( val, PINF, 'returns +infinity' );
166+
t.equal( val, PINF, 'returns expected value' );
167167
t.end();
168168
});
169169

170170
tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) {
171171
var val = exp( NaN );
172-
t.equal( isnan( val ), true, 'returns NaN' );
172+
t.equal( isnan( val ), true, 'returns expected value' );
173173
t.end();
174174
});

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

Lines changed: 4 additions & 3 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 exp10 = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = uniform( 100, -50.0, 50.0 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*100.0 ) - 50.0;
40-
y = exp10( x );
41+
y = exp10( x[ i%x.length ] );
4142
if ( isnan( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}

lib/node_modules/@stdlib/math/base/special/exp10/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, -50.0, 50.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*100.0 ) - 50.0;
49-
y = exp10( x );
50+
y = exp10( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

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

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

0 commit comments

Comments
 (0)