Skip to content

Commit 3de5b71

Browse files
authored
bench: update random value generation
PR-URL: #6158 Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Harsh <[email protected]>
1 parent 44d40da commit 3de5b71

File tree

5 files changed

+54
-49
lines changed

5 files changed

+54
-49
lines changed

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

+5-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 flipsign = require( './../lib' );
@@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
3535
var z;
3636
var i;
3737

38+
x = uniform( 100, -5.0e6, 5.0e6 );
39+
y = uniform( 100, -5.0e6, 5.0e6 );
40+
3841
b.tic();
3942
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*1.0e7 ) - 5.0e6;
41-
y = ( randu()*1.0e7 ) - 5.0e6;
42-
z = flipsign( x, y );
43+
z = flipsign( x[ i%x.length ], y[ i%y.length ] );
4344
if ( isnan( z ) ) {
4445
b.fail( 'should not return NaN' );
4546
}

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

+5-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;
@@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var z;
4545
var i;
4646

47+
x = uniform( 100, -5.0e6, 5.0e6 );
48+
y = uniform( 100, -5.0e6, 5.0e6 );
49+
4750
b.tic();
4851
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*1.0e7 ) - 5.0e6;
50-
y = ( randu()*1.0e7 ) - 5.0e6;
51-
z = flipsign( x, y );
52+
z = flipsign( x[ i%x.length ], y[ i%x.length ] );
5253
if ( isnan( z ) ) {
5354
b.fail( 'should not return NaN' );
5455
}

lib/node_modules/@stdlib/math/base/special/flipsign/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;
95-
double y;
94+
double x[ 100 ];
95+
double y[ 100 ];
9696
double z;
9797
double t;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
102+
y[ i ] = ( 1000.0*rand_double() ) - 500.0;
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( 1000.0*rand_double() ) - 500.0;
103-
y = ( 1000.0*rand_double() ) - 500.0;
104-
z = stdlib_base_flipsign( x, y );
107+
z = stdlib_base_flipsign( 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/flipsign/test/test.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ tape( 'if `x` is `NaN`, the function returns `NaN`', function test( t ) {
6363
var z;
6464

6565
z = flipsign( NaN, -1.0 );
66-
t.equal( isnan( z ), true, 'returns NaN' );
66+
t.equal( isnan( z ), true, 'returns expected value' );
6767

6868
z = flipsign( NaN, 1.0 );
69-
t.equal( isnan( z ), true, 'returns NaN' );
69+
t.equal( isnan( z ), true, 'returns expected value' );
7070

7171
t.end();
7272
});
@@ -75,10 +75,10 @@ tape( 'if `y` is `NaN`, the function could (theoretically) return either a posit
7575
var z;
7676

7777
z = flipsign( -1.0, NaN );
78-
t.equal( isnan( z ), false, 'does not return NaN' );
78+
t.equal( isnan( z ), false, 'returns expected value' );
7979

8080
z = flipsign( 1.0, NaN );
81-
t.equal( isnan( z ), false, 'does not return NaN' );
81+
t.equal( isnan( z ), false, 'returns expected value' );
8282

8383
t.end();
8484
});
@@ -87,10 +87,10 @@ tape( 'if `x` is `+infinity`, the function returns an infinite number', function
8787
var z;
8888

8989
z = flipsign( PINF, -1.0 );
90-
t.equal( z, NINF, 'returns -infinity' );
90+
t.equal( z, NINF, 'returns expected value' );
9191

9292
z = flipsign( PINF, 1.0 );
93-
t.equal( z, PINF, 'returns +infinity' );
93+
t.equal( z, PINF, 'returns expected value' );
9494

9595
t.end();
9696
});
@@ -99,10 +99,10 @@ tape( 'if `y` is `+infinity`, the function returns `x`', function test( t ) {
9999
var z;
100100

101101
z = flipsign( -1.0, PINF );
102-
t.equal( z, -1.0, 'returns -1' );
102+
t.equal( z, -1.0, 'returns expected value' );
103103

104104
z = flipsign( 1.0, PINF );
105-
t.equal( z, 1.0, 'returns +1' );
105+
t.equal( z, 1.0, 'returns expected value' );
106106

107107
t.end();
108108
});
@@ -111,10 +111,10 @@ tape( 'if `x` is `-infinity`, the function returns an infinite number', function
111111
var z;
112112

113113
z = flipsign( NINF, -1.0 );
114-
t.equal( z, PINF, 'returns +infinity' );
114+
t.equal( z, PINF, 'returns expected value' );
115115

116116
z = flipsign( NINF, 1.0 );
117-
t.equal( z, NINF, 'returns -infinity' );
117+
t.equal( z, NINF, 'returns expected value' );
118118

119119
t.end();
120120
});
@@ -123,10 +123,10 @@ tape( 'if `y` is `-infinity`, the function returns `-x`', function test( t ) {
123123
var z;
124124

125125
z = flipsign( -1.0, NINF );
126-
t.equal( z, +1.0, 'returns +1' );
126+
t.equal( z, +1.0, 'returns expected value' );
127127

128128
z = flipsign( 1.0, NINF );
129-
t.equal( z, -1.0, 'returns -1' );
129+
t.equal( z, -1.0, 'returns expected value' );
130130

131131
t.end();
132132
});
@@ -138,10 +138,10 @@ tape( 'the function supports using `+-0` to flip a sign', function test( t ) {
138138
x = 3.14;
139139

140140
z = flipsign( x, 0.0 );
141-
t.equal( z, 3.14, 'returns +3.14' );
141+
t.equal( z, 3.14, 'returns expected value' );
142142

143143
z = flipsign( x, -0.0 );
144-
t.equal( z, -3.14, 'returns -3.14' );
144+
t.equal( z, -3.14, 'returns expected value' );
145145

146146
t.end();
147147
});
@@ -150,16 +150,16 @@ tape( 'the function supports `x` being `+-0`', function test( t ) {
150150
var z;
151151

152152
z = flipsign( -0.0, 1.0 );
153-
t.equal( isNegativeZero( z ), true, 'returns -0' );
153+
t.equal( isNegativeZero( z ), true, 'returns expected value' );
154154

155155
z = flipsign( -0.0, -1.0 );
156-
t.equal( isPositiveZero( z ), true, 'returns +0' );
156+
t.equal( isPositiveZero( z ), true, 'returns expected value' );
157157

158158
z = flipsign( 0.0, 1.0 );
159-
t.equal( isPositiveZero( z ), true, 'returns +0' );
159+
t.equal( isPositiveZero( z ), true, 'returns expected value' );
160160

161161
z = flipsign( 0.0, -1.0 );
162-
t.equal( isNegativeZero( z ), true, 'returns -0' );
162+
t.equal( isNegativeZero( z ), true, 'returns expected value' );
163163

164164
t.end();
165165
});

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ tape( 'if `x` is `NaN`, the function returns `NaN`', opts, function test( t ) {
7272
var z;
7373

7474
z = flipsign( NaN, -1.0 );
75-
t.equal( isnan( z ), true, 'returns NaN' );
75+
t.equal( isnan( z ), true, 'returns expected value' );
7676

7777
z = flipsign( NaN, 1.0 );
78-
t.equal( isnan( z ), true, 'returns NaN' );
78+
t.equal( isnan( z ), true, 'returns expected value' );
7979

8080
t.end();
8181
});
@@ -84,10 +84,10 @@ tape( 'if `y` is `NaN`, the function could (theoretically) return either a posit
8484
var z;
8585

8686
z = flipsign( -1.0, NaN );
87-
t.equal( isnan( z ), false, 'does not return NaN' );
87+
t.equal( isnan( z ), false, 'returns expected value' );
8888

8989
z = flipsign( 1.0, NaN );
90-
t.equal( isnan( z ), false, 'does not return NaN' );
90+
t.equal( isnan( z ), false, 'returns expected value' );
9191

9292
t.end();
9393
});
@@ -96,10 +96,10 @@ tape( 'if `x` is `+infinity`, the function returns an infinite number', opts, fu
9696
var z;
9797

9898
z = flipsign( PINF, -1.0 );
99-
t.equal( z, NINF, 'returns -infinity' );
99+
t.equal( z, NINF, 'returns expected value' );
100100

101101
z = flipsign( PINF, 1.0 );
102-
t.equal( z, PINF, 'returns +infinity' );
102+
t.equal( z, PINF, 'returns expected value' );
103103

104104
t.end();
105105
});
@@ -108,10 +108,10 @@ tape( 'if `y` is `+infinity`, the function returns `x`', opts, function test( t
108108
var z;
109109

110110
z = flipsign( -1.0, PINF );
111-
t.equal( z, -1.0, 'returns -1' );
111+
t.equal( z, -1.0, 'returns expected value' );
112112

113113
z = flipsign( 1.0, PINF );
114-
t.equal( z, 1.0, 'returns +1' );
114+
t.equal( z, 1.0, 'returns expected value' );
115115

116116
t.end();
117117
});
@@ -120,10 +120,10 @@ tape( 'if `x` is `-infinity`, the function returns an infinite number', opts, fu
120120
var z;
121121

122122
z = flipsign( NINF, -1.0 );
123-
t.equal( z, PINF, 'returns +infinity' );
123+
t.equal( z, PINF, 'returns expected value' );
124124

125125
z = flipsign( NINF, 1.0 );
126-
t.equal( z, NINF, 'returns -infinity' );
126+
t.equal( z, NINF, 'returns expected value' );
127127

128128
t.end();
129129
});
@@ -132,10 +132,10 @@ tape( 'if `y` is `-infinity`, the function returns `-x`', opts, function test( t
132132
var z;
133133

134134
z = flipsign( -1.0, NINF );
135-
t.equal( z, +1.0, 'returns +1' );
135+
t.equal( z, +1.0, 'returns expected value' );
136136

137137
z = flipsign( 1.0, NINF );
138-
t.equal( z, -1.0, 'returns -1' );
138+
t.equal( z, -1.0, 'returns expected value' );
139139

140140
t.end();
141141
});
@@ -147,10 +147,10 @@ tape( 'the function supports using `+-0` to flip a sign', opts, function test( t
147147
x = 3.14;
148148

149149
z = flipsign( x, 0.0 );
150-
t.equal( z, 3.14, 'returns +3.14' );
150+
t.equal( z, 3.14, 'returns expected value' );
151151

152152
z = flipsign( x, -0.0 );
153-
t.equal( z, -3.14, 'returns -3.14' );
153+
t.equal( z, -3.14, 'returns expected value' );
154154

155155
t.end();
156156
});
@@ -159,16 +159,16 @@ tape( 'the function supports `x` being `+-0`', opts, function test( t ) {
159159
var z;
160160

161161
z = flipsign( -0.0, 1.0 );
162-
t.equal( isNegativeZero( z ), true, 'returns -0' );
162+
t.equal( isNegativeZero( z ), true, 'returns expected value' );
163163

164164
z = flipsign( -0.0, -1.0 );
165-
t.equal( isPositiveZero( z ), true, 'returns +0' );
165+
t.equal( isPositiveZero( z ), true, 'returns expected value' );
166166

167167
z = flipsign( 0.0, 1.0 );
168-
t.equal( isPositiveZero( z ), true, 'returns +0' );
168+
t.equal( isPositiveZero( z ), true, 'returns expected value' );
169169

170170
z = flipsign( 0.0, -1.0 );
171-
t.equal( isNegativeZero( z ), true, 'returns -0' );
171+
t.equal( isNegativeZero( z ), true, 'returns expected value' );
172172

173173
t.end();
174174
});

0 commit comments

Comments
 (0)