Skip to content

Commit afd63f8

Browse files
authored
bench: update random value generation
PR-URL: #6265 Reviewed-by: Athan Reines <[email protected]>
1 parent cbceb64 commit afd63f8

File tree

8 files changed

+55
-40
lines changed

8 files changed

+55
-40
lines changed

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

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

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

lib/node_modules/@stdlib/math/base/special/haversin/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 ] = ( 20.0*rand_double() ) - 10.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 20.0*rand_double() ) - 10.0;
101-
y = ( 1.0 - cos( x ) ) / 2.0;
104+
y = ( 1.0 - cos( x[ i%100 ] ) ) / 2.0;
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,18 @@ tape( 'the function computes the half-value versed sine (for x >= 2**60 (PI/2) )
199199

200200
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
201201
var v = haversin( NaN );
202-
t.strictEqual( isnan( v ), true, 'returns NaN' );
202+
t.strictEqual( isnan( v ), true, 'returns expected value' );
203203
t.end();
204204
});
205205

206206
tape( 'the function returns `NaN` if provided `+infinity`', function test( t ) {
207207
var v = haversin( PINF );
208-
t.strictEqual( isnan( v ), true, 'returns NaN' );
208+
t.strictEqual( isnan( v ), true, 'returns expected value' );
209209
t.end();
210210
});
211211

212212
tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) {
213213
var v = haversin( NINF );
214-
t.strictEqual( isnan( v ), true, 'returns NaN' );
214+
t.strictEqual( isnan( v ), true, 'returns expected value' );
215215
t.end();
216216
});

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

Lines changed: 13 additions & 9 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 heaviside = 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 = heaviside( x );
41+
y = heaviside( x[ i%x.length ] );
4142
if ( y > 1.0 ) {
4243
b.fail( 'should not return a value greater than 1' );
4344
}
@@ -55,10 +56,11 @@ bench( pkg+'::left-continuous', 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 = heaviside( x, 'left-continuous' );
63+
y = heaviside( x[ i%x.length ], 'left-continuous' );
6264
if ( isnan( y ) ) {
6365
b.fail( 'should not return NaN' );
6466
}
@@ -76,10 +78,11 @@ bench( pkg+'::right-continuous', function benchmark( b ) {
7678
var y;
7779
var i;
7880

81+
x = uniform( 100, -50.0, 50.0 );
82+
7983
b.tic();
8084
for ( i = 0; i < b.iterations; i++ ) {
81-
x = ( randu()*100.0 ) - 50.0;
82-
y = heaviside( x, 'right-continuous' );
85+
y = heaviside( x[ i%x.length ], 'right-continuous' );
8386
if ( isnan( y ) ) {
8487
b.fail( 'should not return NaN' );
8588
}
@@ -97,10 +100,11 @@ bench( pkg+'::half-maximum', function benchmark( b ) {
97100
var y;
98101
var i;
99102

103+
x = uniform( 100, -50.0, 50.0 );
104+
100105
b.tic();
101106
for ( i = 0; i < b.iterations; i++ ) {
102-
x = ( randu()*100.0 ) - 50.0;
103-
y = heaviside( x, 'half-maximum' );
107+
y = heaviside( x[ i%x.length ], 'half-maximum' );
104108
if ( isnan( y ) ) {
105109
b.fail( 'should not return NaN' );
106110
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ double heaviside( double x ) {
103103
*/
104104
static double benchmark( void ) {
105105
double elapsed;
106-
double x;
106+
double x[ 100 ];
107107
double y;
108108
double t;
109109
int i;
110110

111+
for ( i = 0; i < 100; i++ ) {
112+
x[ i ] = ( 100.0*rand_double() ) - 50.0;
113+
}
114+
111115
t = tic();
112116
for ( i = 0; i < ITERATIONS; i++ ) {
113-
x = ( 100.0*rand_double() ) - 50.0;
114-
y = heaviside( x );
117+
y = heaviside( x[ i%100 ] );
115118
if ( y != y ) {
116119
printf( "should not return NaN\n" );
117120
break;

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tape( 'the function returns `0` if `x` is negative', function test( t ) {
4646
for ( i = 0; i < 1e3; i++ ) {
4747
x = -( randu()*100.0 ) - EPS;
4848
v = heaviside( x );
49-
t.equal( isPositiveZero( v ), true, 'returns 0 when provided '+x );
49+
t.equal( isPositiveZero( v ), true, 'returns expected value when provided '+x );
5050
}
5151
t.end();
5252
});
@@ -59,7 +59,7 @@ tape( 'the function returns `1` if `x` is positive', function test( t ) {
5959
for ( i = 0; i < 1e3; i++ ) {
6060
x = ( randu()*100.0 ) + EPS;
6161
v = heaviside( x );
62-
t.equal( v, 1.0, 'returns 1 when provided '+x );
62+
t.equal( v, 1.0, 'returns expected value when provided '+x );
6363
}
6464
t.end();
6565
});
@@ -68,10 +68,10 @@ tape( 'by default, the function returns `NaN` if provided `+-0`', function test(
6868
var v;
6969

7070
v = heaviside( -0.0 );
71-
t.equal( isnan( v ), true, 'returns NaN' );
71+
t.equal( isnan( v ), true, 'returns expected value' );
7272

7373
v = heaviside( +0.0 );
74-
t.equal( isnan( v ), true, 'returns NaN' );
74+
t.equal( isnan( v ), true, 'returns expected value' );
7575

7676
t.end();
7777
});
@@ -80,10 +80,10 @@ tape( 'if the `continuity` option is `half-maximum`, the function returns `0.5`
8080
var v;
8181

8282
v = heaviside( -0.0, 'half-maximum' );
83-
t.equal( v, 0.5, 'returns 1/2' );
83+
t.equal( v, 0.5, 'returns expected value' );
8484

8585
v = heaviside( +0.0, 'half-maximum' );
86-
t.equal( v, 0.5, 'returns 1/2' );
86+
t.equal( v, 0.5, 'returns expected value' );
8787

8888
t.end();
8989
});
@@ -92,10 +92,10 @@ tape( 'if the `continuity` option is `left-continuous`, the function returns `0.
9292
var v;
9393

9494
v = heaviside( -0.0, 'left-continuous' );
95-
t.equal( isPositiveZero( v ), true, 'returns 0' );
95+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
9696

9797
v = heaviside( +0.0, 'left-continuous' );
98-
t.equal( isPositiveZero( v ), true, 'returns 0' );
98+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
9999

100100
t.end();
101101
});
@@ -104,28 +104,28 @@ tape( 'if the `continuity` option is `right-continuous`, the function returns `1
104104
var v;
105105

106106
v = heaviside( -0.0, 'right-continuous' );
107-
t.equal( v, 1, 'returns 1' );
107+
t.equal( v, 1, 'returns expected value' );
108108

109109
v = heaviside( +0.0, 'right-continuous' );
110-
t.equal( v, 1, 'returns 1' );
110+
t.equal( v, 1, 'returns expected value' );
111111

112112
t.end();
113113
});
114114

115115
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
116116
var v = heaviside( NaN );
117-
t.equal( isnan( v ), true, 'returns NaN' );
117+
t.equal( isnan( v ), true, 'returns expected value' );
118118
t.end();
119119
});
120120

121121
tape( 'the function returns `0` if provided `-infinity`', function test( t ) {
122122
var v = heaviside( NINF );
123-
t.equal( v, 0.0, 'returns 0' );
123+
t.equal( v, 0.0, 'returns expected value' );
124124
t.end();
125125
});
126126

127127
tape( 'the function returns `+1` if provided `+infinity`', function test( t ) {
128128
var v = heaviside( PINF );
129-
t.equal( v, 1.0, 'returns 1' );
129+
t.equal( v, 1.0, 'returns expected value' );
130130
t.end();
131131
});

0 commit comments

Comments
 (0)