Skip to content

Commit c52b2f9

Browse files
bench: update random value generation
PR-URL: #5390 Reviewed-by: Athan Reines <[email protected]>
1 parent de3e20c commit c52b2f9

File tree

20 files changed

+76
-52
lines changed

20 files changed

+76
-52
lines changed

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

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

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ static double rand_double( void ) {
8989
* @return elapsed time in seconds
9090
*/
9191
static double benchmark( void ) {
92+
double x[ 100 ];
9293
double elapsed;
93-
double x;
9494
double y;
9595
double t;
9696
int i;
9797

98+
for ( i = 0; i < 100; i++ ) {
99+
x[ i ] = rand_double();
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = rand_double();
101-
y = 2.0 * acos( sqrt( x ) );
104+
y = 2.0 * acos( sqrt( x[ i%100 ] ) );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double y;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = rand_double();
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = rand_double();
102-
y = stdlib_base_ahavercos( x );
105+
y = stdlib_base_ahavercos( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ tape( 'the function computes the inverse half-value versed cosine (small positiv
9292

9393
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
9494
var v = ahavercos( NaN );
95-
t.strictEqual( isnan( v ), true, 'returns NaN' );
95+
t.strictEqual( isnan( v ), true, 'returns expected value' );
9696
t.end();
9797
});
9898

@@ -101,7 +101,7 @@ tape( 'the function returns `NaN` if provided a value less than `0`', function t
101101
var i;
102102
for ( i = 0; i < 1e4; i++ ) {
103103
v = -(randu()*1.0e6) - EPS;
104-
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns NaN when provided '+v );
104+
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns expected value when provided '+v );
105105
}
106106
t.end();
107107
});
@@ -111,7 +111,7 @@ tape( 'the function returns `NaN` if provided a value greater than `1`', functio
111111
var i;
112112
for ( i = 0; i < 1e4; i++ ) {
113113
v = (randu()*1.0e6) + 1.0 + EPS;
114-
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns NaN when provided '+v );
114+
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns expected value when provided '+v );
115115
}
116116
t.end();
117117
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ tape( 'the function computes the inverse half-value versed cosine (small positiv
101101

102102
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
103103
var v = ahavercos( NaN );
104-
t.strictEqual( isnan( v ), true, 'returns NaN' );
104+
t.strictEqual( isnan( v ), true, 'returns expected value' );
105105
t.end();
106106
});
107107

@@ -110,7 +110,7 @@ tape( 'the function returns `NaN` if provided a value less than `0`', opts, func
110110
var i;
111111
for ( i = 0; i < 1e4; i++ ) {
112112
v = -(randu()*1.0e6) - EPS;
113-
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns NaN when provided '+v );
113+
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns expected value when provided '+v );
114114
}
115115
t.end();
116116
});
@@ -120,7 +120,7 @@ tape( 'the function returns `NaN` if provided a value greater than `1`', opts, f
120120
var i;
121121
for ( i = 0; i < 1e4; i++ ) {
122122
v = (randu()*1.0e6) + 1.0 + EPS;
123-
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns NaN when provided '+v );
123+
t.strictEqual( isnan( ahavercos( v ) ), true, 'returns expected value when provided '+v );
124124
}
125125
t.end();
126126
});

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

Lines changed: 4 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var ahavercosf = require( './../lib' );
@@ -34,7 +34,9 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37-
x = randu( 100, 0.0, 1.0 );
37+
x = uniform( 100, 0.0, 1.0, {
38+
'dtype': 'float32'
39+
});
3840

3941
b.tic();
4042
for ( i = 0; i < b.iterations; i++ ) {

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

Lines changed: 4 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,7 +43,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = randu( 100, 0.0, 1.0 );
46+
x = uniform( 100, 0.0, 1.0, {
47+
'dtype': 'float32'
48+
});
4749

4850
b.tic();
4951
for ( i = 0; i < b.iterations; i++ ) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ static float rand_float( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
float x[ 100 ];
9493
double t;
94+
float x[ 100 ];
9595
float y;
9696
int i;
9797

@@ -101,7 +101,7 @@ static double benchmark( void ) {
101101

102102
t = tic();
103103
for ( i = 0; i < ITERATIONS; i++ ) {
104-
y = 2.0f * acosf( sqrtf( x[ i % 100 ] ) );
104+
y = 2.0f * acosf( sqrtf( x[ i%100 ] ) );
105105
if ( y != y ) {
106106
printf( "should not return NaN\n" );
107107
break;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ static float rand_float( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
float x[ 100 ];
9594
double t;
95+
float x[ 100 ];
9696
float y;
9797
int i;
9898

@@ -102,7 +102,7 @@ static double benchmark( void ) {
102102

103103
t = tic();
104104
for ( i = 0; i < ITERATIONS; i++ ) {
105-
y = stdlib_base_ahavercosf( x[ i % 100 ] );
105+
y = stdlib_base_ahavercosf( x[ i%100 ] );
106106
if ( y != y ) {
107107
printf( "should not return NaN\n" );
108108
break;

0 commit comments

Comments
 (0)