Skip to content

Commit 0283c27

Browse files
authored
bench: update random value generation
PR-URL: #6649 Reviewed-by: Athan Reines <[email protected]>
1 parent b2f8db2 commit 0283c27

File tree

15 files changed

+127
-92
lines changed

15 files changed

+127
-92
lines changed

lib/node_modules/@stdlib/math/base/special/fast/atanh/benchmark/benchmark.js

+6-3
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 atanh = require( './../lib' );
@@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = uniform( 100, -1.0, 1.0, {
38+
'dtype': 'float64'
39+
});
40+
3741
b.tic();
3842
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*2.0 ) - 1.0;
40-
y = atanh( x );
43+
y = atanh( x[ i%x.length ] );
4144
if ( isnan( y ) ) {
4245
b.fail( 'should not return NaN' );
4346
}

lib/node_modules/@stdlib/math/base/special/fast/atanh/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 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,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

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

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

lib/node_modules/@stdlib/math/base/special/fast/atanh/test/test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,26 @@ tape( 'the function computes the hyperbolic arctangent (positive values)', funct
9797
tape( 'the function underflows if provided a value negligible compared to unity (negative)', function test( t ) {
9898
var x = -EPS / 10.0;
9999
var v = atanh( x );
100-
t.strictEqual( isPositiveZero( v ), true, 'returns 0' );
100+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
101101
t.end();
102102
});
103103

104104
tape( 'the function underflows if provided a value negligible compared to unity (positive)', function test( t ) {
105105
var x = EPS / 10.0;
106106
var v = atanh( x );
107-
t.strictEqual( isPositiveZero( v ), true, 'returns 0' );
107+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
108108
t.end();
109109
});
110110

111111
tape( 'the function returns `+Infinity` if provided `1.0`', function test( t ) {
112112
var v = atanh( 1.0 );
113-
t.strictEqual( v, PINF, 'returns +Infinity' );
113+
t.strictEqual( v, PINF, 'returns expected value' );
114114
t.end();
115115
});
116116

117117
tape( 'the function returns `-Infinity` if provided `-1.0`', function test( t ) {
118118
var v = atanh( -1.0 );
119-
t.strictEqual( v, NINF, 'returns -Infinity' );
119+
t.strictEqual( v, NINF, 'returns expected value' );
120120
t.end();
121121
});
122122

@@ -126,7 +126,7 @@ tape( 'the function returns `NaN` if provided a value less than `-1`', function
126126

127127
for ( i = 0; i < 1e3; i++ ) {
128128
v = -(randu()*1.0e6) - (1.0+EPS);
129-
t.strictEqual( isnan( atanh( v ) ), true, 'returns NaN when provided '+v );
129+
t.strictEqual( isnan( atanh( v ) ), true, 'returns expected value when provided '+v );
130130
}
131131
t.end();
132132
});
@@ -137,25 +137,25 @@ tape( 'the function returns `NaN` if provided a value greater than `1`', functio
137137

138138
for ( i = 0; i < 1e3; i++ ) {
139139
v = ( randu()*1.0e6 ) + 1.0 + EPS;
140-
t.strictEqual( isnan( atanh( v ) ), true, 'returns NaN when provided '+v );
140+
t.strictEqual( isnan( atanh( v ) ), true, 'returns expected value when provided '+v );
141141
}
142142
t.end();
143143
});
144144

145145
tape( 'the function returns `-0` if provided `-0`', function test( t ) {
146146
var v = atanh( -0.0 );
147-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
147+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
148148
t.end();
149149
});
150150

151151
tape( 'the function returns `+0` if provided `+0`', function test( t ) {
152152
var v = atanh( 0.0 );
153-
t.strictEqual( isPositiveZero( v ), true, 'returns 0' );
153+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
154154
t.end();
155155
});
156156

157157
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
158158
var v = atanh( NaN );
159-
t.strictEqual( isnan( v ), true, 'returns NaN' );
159+
t.strictEqual( isnan( v ), true, 'returns expected value' );
160160
t.end();
161161
});

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,26 @@ tape( 'the function computes the hyperbolic arctangent (positive values)', opts,
106106
tape( 'the function underflows if provided a value negligible compared to unity (negative)', opts, function test( t ) {
107107
var x = -EPS / 10.0;
108108
var v = atanh( x );
109-
t.strictEqual( isPositiveZero( v ), true, 'returns 0' );
109+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
110110
t.end();
111111
});
112112

113113
tape( 'the function underflows if provided a value negligible compared to unity (positive)', opts, function test( t ) {
114114
var x = EPS / 10.0;
115115
var v = atanh( x );
116-
t.strictEqual( isPositiveZero( v ), true, 'returns 0' );
116+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
117117
t.end();
118118
});
119119

120120
tape( 'the function returns `+Infinity` if provided `1.0`', opts, function test( t ) {
121121
var v = atanh( 1.0 );
122-
t.strictEqual( v, PINF, 'returns +Infinity' );
122+
t.strictEqual( v, PINF, 'returns expected value' );
123123
t.end();
124124
});
125125

126126
tape( 'the function returns `-Infinity` if provided `-1.0`', opts, function test( t ) {
127127
var v = atanh( -1.0 );
128-
t.strictEqual( v, NINF, 'returns -Infinity' );
128+
t.strictEqual( v, NINF, 'returns expected value' );
129129
t.end();
130130
});
131131

@@ -135,7 +135,7 @@ tape( 'the function returns `NaN` if provided a value less than `-1`', opts, fun
135135

136136
for ( i = 0; i < 1e3; i++ ) {
137137
v = -(randu()*1.0e6) - (1.0+EPS);
138-
t.strictEqual( isnan( atanh( v ) ), true, 'returns NaN when provided '+v );
138+
t.strictEqual( isnan( atanh( v ) ), true, 'returns expected value when provided '+v );
139139
}
140140
t.end();
141141
});
@@ -146,25 +146,25 @@ tape( 'the function returns `NaN` if provided a value greater than `1`', opts, f
146146

147147
for ( i = 0; i < 1e3; i++ ) {
148148
v = ( randu()*1.0e6 ) + 1.0 + EPS;
149-
t.strictEqual( isnan( atanh( v ) ), true, 'returns NaN when provided '+v );
149+
t.strictEqual( isnan( atanh( v ) ), true, 'returns expected value when provided '+v );
150150
}
151151
t.end();
152152
});
153153

154154
tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) {
155155
var v = atanh( -0.0 );
156-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
156+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
157157
t.end();
158158
});
159159

160160
tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) {
161161
var v = atanh( 0.0 );
162-
t.strictEqual( isPositiveZero( v ), true, 'returns 0' );
162+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
163163
t.end();
164164
});
165165

166166
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
167167
var v = atanh( NaN );
168-
t.strictEqual( isnan( v ), true, 'returns NaN' );
168+
t.strictEqual( isnan( v ), true, 'returns expected value' );
169169
t.end();
170170
});

lib/node_modules/@stdlib/math/base/special/fast/max/benchmark/benchmark.js

+9-4
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 max = require( './../lib' );
@@ -30,16 +30,21 @@ var max = require( './../lib' );
3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33+
var opts;
3334
var x;
3435
var y;
3536
var z;
3637
var i;
3738

39+
opts = {
40+
'dtype': 'float64'
41+
};
42+
x = uniform( 100, -5000.0, 5000.0, opts );
43+
y = uniform( 100, -5000.0, 5000.0, opts );
44+
3845
b.tic();
3946
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*10000.0 ) - 5000.0;
41-
y = ( randu()*10000.0 ) - 5000.0;
42-
z = max( x, y );
47+
z = max( x[ i%x.length ], y[ i%y.length ] );
4348
if ( isnan( z ) ) {
4449
b.fail( 'should not return NaN' );
4550
}

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

+9-4
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;
@@ -39,16 +39,21 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var opts;
4243
var x;
4344
var y;
4445
var z;
4546
var i;
4647

48+
opts = {
49+
'dtype': 'float64'
50+
};
51+
x = uniform( 100, -1000.0, 1000.0, opts );
52+
y = uniform( 100, -1000.0, 1000.0, opts );
53+
4754
b.tic();
4855
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*2000.0 ) - 1000.0;
50-
y = ( randu()*2000.0 ) - 1000.0;
51-
z = max( x, y );
56+
z = max( x[ i%x.length ], y[ i%y.length ] );
5257
if ( isnan( z ) ) {
5358
b.fail( 'should not return NaN' );
5459
}

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94+
double x[ 100 ];
95+
double y[ 100 ];
9496
double t;
95-
double x;
96-
double y;
9797
double z;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 2000.0*rand_double() ) - 1000.0;
102+
y[ i ] = ( 2000.0*rand_double() ) - 1000.0;
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( 2000.0*rand_double() ) - 1000.0;
103-
y = ( 2000.0*rand_double() ) - 1000.0;
104-
z = stdlib_base_fast_max( x, y );
107+
z = stdlib_base_fast_max( x[ i%100 ], y[ i%100 ] );
105108
if ( z != z ) {
106109
printf( "should not return NaN\n" );
107110
break;

lib/node_modules/@stdlib/math/base/special/fast/max/test/test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ tape( 'the function may not return `NaN` if provided a `NaN`', function test( t
4545
var v;
4646

4747
v = max( NaN, 3.14 );
48-
t.strictEqual( v, 3.14, 'returns 3.14' );
48+
t.strictEqual( v, 3.14, 'returns expected value' );
4949

5050
v = max( 3.14, NaN );
51-
t.strictEqual( isnan( v ), true, 'returns NaN' );
51+
t.strictEqual( isnan( v ), true, 'returns expected value' );
5252

5353
t.end();
5454
});
@@ -57,10 +57,10 @@ tape( 'the function returns `+infinity` if provided `+infinity`', function test(
5757
var v;
5858

5959
v = max( PINF, 3.14 );
60-
t.strictEqual( v, PINF, 'returns +infinity' );
60+
t.strictEqual( v, PINF, 'returns expected value' );
6161

6262
v = max( 3.14, PINF );
63-
t.strictEqual( v, PINF, 'returns +infinity' );
63+
t.strictEqual( v, PINF, 'returns expected value' );
6464

6565
t.end();
6666
});
@@ -69,16 +69,16 @@ tape( 'the function may not return a correctly signed zero', function test( t )
6969
var v;
7070

7171
v = max( +0.0, -0.0 );
72-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
72+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
7373

7474
v = max( -0.0, +0.0 );
75-
t.strictEqual( isNegativeZero( v ), false, 'does not return -0' );
75+
t.strictEqual( isNegativeZero( v ), false, 'returns expected value' );
7676

7777
v = max( -0.0, -0.0 );
78-
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
78+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
7979

8080
v = max( +0.0, +0.0 );
81-
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
81+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
8282

8383
t.end();
8484
});
@@ -87,10 +87,10 @@ tape( 'the function returns the maximum value', function test( t ) {
8787
var v;
8888

8989
v = max( 4.2, 3.14 );
90-
t.strictEqual( v, 4.2, 'returns max value' );
90+
t.strictEqual( v, 4.2, 'returns expected value' );
9191

9292
v = max( -4.2, 3.14 );
93-
t.strictEqual( v, 3.14, 'returns max value' );
93+
t.strictEqual( v, 3.14, 'returns expected value' );
9494

9595
t.end();
9696
});

0 commit comments

Comments
 (0)