Skip to content

Commit e0d7522

Browse files
hrshyakgryte
andauthored
bench: update random value generation
PR-URL: #6327 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent 56b84a4 commit e0d7522

File tree

19 files changed

+90
-69
lines changed

19 files changed

+90
-69
lines changed

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

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

lib/node_modules/@stdlib/math/base/special/erfc/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 = erfc( x );
50+
y = erfc( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

lib/node_modules/@stdlib/math/base/special/erfc/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 ] = ( 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 = erfc( x );
104+
y = erfc( x[ i%100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

lib/node_modules/@stdlib/math/base/special/erfc/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 ] = ( 2.0*rand_double() ) - 1.0;
105+
}
106+
103107
t = tic();
104108
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = ( 2.0*rand_double() ) - 1.0;
106-
y = erfc( x );
109+
y = erfc( x[ i%100 ] );
107110
if ( y != y ) {
108111
printf( "should not return NaN\n" );
109112
break;

lib/node_modules/@stdlib/math/base/special/erfc/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 ] = ( 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_erfc( x );
105+
y = stdlib_base_erfc( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,30 +291,30 @@ tape( 'the function evaluates the complementary error function for subnormal `x`
291291

292292
tape( 'if provided `-0`, the function returns `1`', function test( t ) {
293293
var y = erfc( -0.0 );
294-
t.equal( y, 1.0, 'returns 1' );
294+
t.equal( y, 1.0, 'returns expected value' );
295295
t.end();
296296
});
297297

298298
tape( 'if provided `+0`, the function returns `1`', function test( t ) {
299299
var y = erfc( +0.0 );
300-
t.equal( y, 1.0, 'returns 1' );
300+
t.equal( y, 1.0, 'returns expected value' );
301301
t.end();
302302
});
303303

304304
tape( 'if provided `-infinity`, the function returns `2`', function test( t ) {
305305
var y = erfc( NINF );
306-
t.equal( y, 2.0, 'returns 2' );
306+
t.equal( y, 2.0, 'returns expected value' );
307307
t.end();
308308
});
309309

310310
tape( 'if provided `+infinity`, the function returns `0`', function test( t ) {
311311
var y = erfc( PINF );
312-
t.equal( y, 0.0, 'returns 0' );
312+
t.equal( y, 0.0, 'returns expected value' );
313313
t.end();
314314
});
315315

316316
tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
317317
var y = erfc( NaN );
318-
t.equal( isnan( y ), true, 'returns NaN' );
318+
t.equal( isnan( y ), true, 'returns expected value' );
319319
t.end();
320320
});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,30 +300,30 @@ tape( 'the function evaluates the complementary error function for subnormal `x`
300300

301301
tape( 'if provided `-0`, the function returns `1`', opts, function test( t ) {
302302
var y = erfc( -0.0 );
303-
t.equal( y, 1.0, 'returns 1' );
303+
t.equal( y, 1.0, 'returns expected value' );
304304
t.end();
305305
});
306306

307307
tape( 'if provided `+0`, the function returns `1`', opts, function test( t ) {
308308
var y = erfc( +0.0 );
309-
t.equal( y, 1.0, 'returns 1' );
309+
t.equal( y, 1.0, 'returns expected value' );
310310
t.end();
311311
});
312312

313313
tape( 'if provided `-infinity`, the function returns `2`', opts, function test( t ) {
314314
var y = erfc( NINF );
315-
t.equal( y, 2.0, 'returns 2' );
315+
t.equal( y, 2.0, 'returns expected value' );
316316
t.end();
317317
});
318318

319319
tape( 'if provided `+infinity`, the function returns `0`', opts, function test( t ) {
320320
var y = erfc( PINF );
321-
t.equal( y, 0.0, 'returns 0' );
321+
t.equal( y, 0.0, 'returns expected value' );
322322
t.end();
323323
});
324324

325325
tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) {
326326
var y = erfc( NaN );
327-
t.equal( isnan( y ), true, 'returns NaN' );
327+
t.equal( isnan( y ), true, 'returns expected value' );
328328
t.end();
329329
});

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

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

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

lib/node_modules/@stdlib/math/base/special/erfcinv/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 ] = ( 2.0 * rand_double() ) - 0.0;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 2.0 * rand_double() ) - 0.0;
102-
y = stdlib_base_erfcinv( x );
105+
y = stdlib_base_erfcinv( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ tape( 'main export is a function', function test( t ) {
5151

5252
tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
5353
var y = erfcinv( NaN );
54-
t.equal( isnan( y ), true, 'returns NaN' );
54+
t.equal( isnan( y ), true, 'returns expected value' );
5555
t.end();
5656
});
5757

5858
tape( 'if provided `0`, the function returns `+infinity`', function test( t ) {
5959
var y = erfcinv( 0.0 );
60-
t.equal( y, PINF, 'returns +infinity' );
60+
t.equal( y, PINF, 'returns expected value' );
6161
t.end();
6262
});
6363

6464
tape( 'if provided `2`, the function returns `-infinity`', function test( t ) {
6565
var y = erfcinv( 2.0 );
66-
t.equal( y, NINF, 'returns `-infinity`' );
66+
t.equal( y, NINF, 'returns expected value`' );
6767
t.end();
6868
});
6969

7070
tape( 'if provided `1`, the function returns `0`', function test( t ) {
7171
var y = erfcinv( 1.0 );
72-
t.equal( isPositiveZero( y ), true, 'returns `+0`' );
72+
t.equal( isPositiveZero( y ), true, 'returns expected value`' );
7373
t.end();
7474
});
7575

@@ -89,7 +89,7 @@ tape( 'if provided a value which is either less than `0` or greater than `2`, th
8989

9090
for ( i = 0; i < values.length; i++ ) {
9191
v = erfcinv( values[i] );
92-
t.equal( isnan( v ), true, 'returns NaN when provided '+values[i] );
92+
t.equal( isnan( v ), true, 'returns expected value when provided '+values[i] );
9393
}
9494
t.end();
9595
});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@ tape( 'main export is a function', opts, function test( t ) {
6060

6161
tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) {
6262
var y = erfcinv( NaN );
63-
t.equal( isnan( y ), true, 'returns NaN' );
63+
t.equal( isnan( y ), true, 'returns expected value' );
6464
t.end();
6565
});
6666

6767
tape( 'if provided `0`, the function returns `+infinity`', opts, function test( t ) {
6868
var y = erfcinv( 0.0 );
69-
t.equal( y, PINF, 'returns +infinity' );
69+
t.equal( y, PINF, 'returns expected value' );
7070
t.end();
7171
});
7272

7373
tape( 'if provided `2`, the function returns `-infinity`', opts, function test( t ) {
7474
var y = erfcinv( 2.0 );
75-
t.equal( y, NINF, 'returns `-infinity`' );
75+
t.equal( y, NINF, 'returns expected value' );
7676
t.end();
7777
});
7878

7979
tape( 'if provided `1`, the function returns `0`', opts, function test( t ) {
8080
var y = erfcinv( 1.0 );
81-
t.equal( isPositiveZero( y ), true, 'returns `+0`' );
81+
t.equal( isPositiveZero( y ), true, 'returns expected value`' );
8282
t.end();
8383
});
8484

@@ -98,7 +98,7 @@ tape( 'if provided a value which is either less than `0` or greater than `2`, th
9898

9999
for ( i = 0; i < values.length; i++ ) {
100100
v = erfcinv( values[i] );
101-
t.equal( isnan( v ), true, 'returns NaN when provided '+values[i] );
101+
t.equal( isnan( v ), true, 'returns expected value when provided '+values[i] );
102102
}
103103
t.end();
104104
});

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

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

37-
x = randu( 100, -100.0, 100.0 );
37+
x = uniform( 100, -100.0, 100.0 );
3838

3939
b.tic();
4040
for ( i = 0; i < b.iterations; i++ ) {

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

Lines changed: 2 additions & 2 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/array/uniform' );
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,7 +43,7 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = randu( 100, -100.0, 100.0 );
46+
x = uniform( 100, -100.0, 100.0 );
4747

4848
b.tic();
4949
for ( i = 0; i < b.iterations; i++ ) {

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

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

0 commit comments

Comments
 (0)