21
21
// MODULES //
22
22
23
23
var bench = require ( '@stdlib/bench' ) ;
24
- var randu = require ( '@stdlib/random/base/randu ' ) ;
24
+ var uniform = require ( '@stdlib/random/array/uniform ' ) ;
25
25
var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
26
26
var sinpi = require ( '@stdlib/math/base/special/sinpi' ) ;
27
27
var cospi = require ( '@stdlib/math/base/special/cospi' ) ;
@@ -37,10 +37,11 @@ bench( pkg, function benchmark( b ) {
37
37
var y ;
38
38
var i ;
39
39
40
+ x = uniform ( 100 , - 10.0 , 10.0 ) ;
41
+
40
42
b . tic ( ) ;
41
43
for ( i = 0 ; i < b . iterations ; i ++ ) {
42
- x = ( randu ( ) * 20.0 ) - 10.0 ;
43
- y = sincospi ( x ) ;
44
+ y = sincospi ( x [ i % x . length ] ) ;
44
45
if ( isnan ( y [ 0 ] ) || isnan ( y [ 1 ] ) ) {
45
46
b . fail ( 'should not return NaN' ) ;
46
47
}
@@ -58,11 +59,12 @@ bench( pkg+'::separate-evaluation', function benchmark( b ) {
58
59
var y ;
59
60
var i ;
60
61
62
+ x = uniform ( 100 , - 10.0 , 10.0 ) ;
61
63
y = [ 0.0 , 0.0 ] ;
64
+
62
65
b . tic ( ) ;
63
66
for ( i = 0 ; i < b . iterations ; i ++ ) {
64
- x = ( randu ( ) * 20.0 ) - 10.0 ;
65
- y = [ sinpi ( x ) , cospi ( x ) ] ;
67
+ y = [ sinpi ( x [ i % x . length ] ) , cospi ( x [ i % x . length ] ) ] ;
66
68
if ( isnan ( y [ 0 ] ) || isnan ( y [ 1 ] ) ) {
67
69
b . fail ( 'should not return NaN' ) ;
68
70
}
@@ -80,11 +82,12 @@ bench( pkg+':assign', function benchmark( b ) {
80
82
var y ;
81
83
var i ;
82
84
85
+ x = uniform ( 100 , - 10.0 , 10.0 ) ;
83
86
y = [ 0.0 , 0.0 ] ;
87
+
84
88
b . tic ( ) ;
85
89
for ( i = 0 ; i < b . iterations ; i ++ ) {
86
- x = ( randu ( ) * 20.0 ) - 10.0 ;
87
- sincospi . assign ( x , y , 1 , 0 ) ;
90
+ sincospi . assign ( x [ i % x . length ] , y , 1 , 0 ) ;
88
91
if ( isnan ( y [ 0 ] ) || isnan ( y [ 1 ] ) ) {
89
92
b . fail ( 'should not return NaN' ) ;
90
93
}
@@ -102,12 +105,13 @@ bench( pkg+'::separate-evaluation,in-place', function benchmark( b ) {
102
105
var y ;
103
106
var i ;
104
107
108
+ x = uniform ( 100 , - 10.0 , 10.0 ) ;
105
109
y = [ 0.0 , 0.0 ] ;
110
+
106
111
b . tic ( ) ;
107
112
for ( i = 0 ; i < b . iterations ; i ++ ) {
108
- x = ( randu ( ) * 20.0 ) - 10.0 ;
109
- y [ 0 ] = sinpi ( x ) ;
110
- y [ 1 ] = cospi ( x ) ;
113
+ y [ 0 ] = sinpi ( x [ i % x . length ] ) ;
114
+ y [ 1 ] = cospi ( x [ i % x . length ] ) ;
111
115
if ( isnan ( y [ 0 ] ) || isnan ( y [ 1 ] ) ) {
112
116
b . fail ( 'should not return NaN' ) ;
113
117
}
@@ -125,10 +129,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
125
129
var y ;
126
130
var i ;
127
131
132
+ x = uniform ( 100 , - 10.0 , 10.0 ) ;
133
+
128
134
b . tic ( ) ;
129
135
for ( i = 0 ; i < b . iterations ; i ++ ) {
130
- x = ( randu ( ) * 20.0 ) - 10.0 ;
131
- y = [ Math . sin ( PI * x ) , Math . cos ( PI * x ) ] ; // eslint-disable-line stdlib/no-builtin-math
136
+ y = [ Math . sin ( PI * x [ i % x . length ] ) , Math . cos ( PI * x [ i % x . length ] ) ] ; // eslint-disable-line stdlib/no-builtin-math
132
137
if ( isnan ( y [ 0 ] ) || isnan ( y [ 1 ] ) ) {
133
138
b . fail ( 'should not return NaN' ) ;
134
139
}
@@ -146,12 +151,13 @@ bench( pkg+'::built-in,in-place', function benchmark( b ) {
146
151
var y ;
147
152
var i ;
148
153
154
+ x = uniform ( 100 , - 10.0 , 10.0 ) ;
149
155
y = [ 0.0 , 0.0 ] ;
156
+
150
157
b . tic ( ) ;
151
158
for ( i = 0 ; i < b . iterations ; i ++ ) {
152
- x = ( randu ( ) * 20.0 ) - 10.0 ;
153
- y [ 0 ] = Math . sin ( PI * x ) ; // eslint-disable-line stdlib/no-builtin-math
154
- y [ 1 ] = Math . cos ( PI * x ) ; // eslint-disable-line stdlib/no-builtin-math
159
+ y [ 0 ] = Math . sin ( PI * x [ i % x . length ] ) ; // eslint-disable-line stdlib/no-builtin-math
160
+ y [ 1 ] = Math . cos ( PI * x [ i % x . length ] ) ; // eslint-disable-line stdlib/no-builtin-math
155
161
if ( isnan ( y [ 0 ] ) || isnan ( y [ 1 ] ) ) {
156
162
b . fail ( 'should not return NaN' ) ;
157
163
}
0 commit comments