Skip to content

Commit 141105c

Browse files
bench: refactor benchmarks and update test messages in math/base/special/acosd
PR-URL: #5268 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent cfada54 commit 141105c

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

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

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

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ tape( 'main export is a function', function test( t ) {
4444

4545
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
4646
var v = acosd( NaN );
47-
t.equal( isnan( v ), true, 'returns NaN' );
47+
t.equal( isnan( v ), true, 'returns expected value' );
4848
t.end();
4949
});
5050

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

103103
for ( i = 0; i < 1e3; i++ ) {
104104
v = -(randu()*1.0e6) - (1.0-EPS);
105-
t.equal( isnan( acosd( v ) ), true, 'returns NaN when provided '+v );
105+
t.equal( isnan( acosd( v ) ), true, 'returns expected value when provided '+v );
106106
}
107107
t.end();
108108
});
@@ -113,7 +113,7 @@ tape( 'the function returns `NaN` if provided a value greater than `+1`', functi
113113

114114
for ( i = 0; i < 1e3; i++ ) {
115115
v = (randu()*1.0e6) + 1.0 + EPS;
116-
t.equal( isnan( acosd( v ) ), true, 'returns NaN when provided '+v );
116+
t.equal( isnan( acosd( v ) ), true, 'returns expected value when provided '+v );
117117
}
118118
t.end();
119119
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tape( 'main export is a function', opts, function test( t ) {
5353

5454
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
5555
var v = acosd( NaN );
56-
t.equal( isnan( v ), true, 'returns NaN' );
56+
t.equal( isnan( v ), true, 'returns expected value' );
5757
t.end();
5858
});
5959

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

112112
for ( i = 0; i < 1e3; i++ ) {
113113
v = -(randu()*1.0e6) - (1.0-EPS);
114-
t.equal( isnan( acosd( v ) ), true, 'returns NaN when provided '+v );
114+
t.equal( isnan( acosd( v ) ), true, 'returns expected value when provided '+v );
115115
}
116116
t.end();
117117
});
@@ -122,7 +122,7 @@ tape( 'the function returns `NaN` if provided a value greater than `+1`', opts,
122122

123123
for ( i = 0; i < 1e3; i++ ) {
124124
v = (randu()*1.0e6) + 1.0 + EPS;
125-
t.equal( isnan( acosd( v ) ), true, 'returns NaN when provided '+v );
125+
t.equal( isnan( acosd( v ) ), true, 'returns expected value when provided '+v );
126126
}
127127
t.end();
128128
});

0 commit comments

Comments
 (0)