2121// MODULES //
2222
2323var bench = require ( '@stdlib/bench' ) ;
24- var randu = require ( '@stdlib/random/base/randu ' ) ;
25- var ceilf = require ( '@stdlib/math/base/special/ceilf ' ) ;
24+ var uniform = require ( '@stdlib/random/array/uniform ' ) ;
25+ var discreteUniform = require ( '@stdlib/random/array/discrete-uniform ' ) ;
2626var isnanf = require ( '@stdlib/math/base/assert/is-nanf' ) ;
2727var f32 = require ( '@stdlib/number/float64/base/to-float32' ) ;
2828var pkg = require ( './../package.json' ) . name ;
@@ -32,16 +32,21 @@ var ampbmf = require( './../lib' );
3232// MAIN //
3333
3434bench ( pkg , function benchmark ( b ) {
35+ var opts ;
3536 var x ;
3637 var y ;
3738 var h ;
3839 var i ;
3940
41+ opts = {
42+ 'dtype' : 'float32'
43+ } ;
44+ x = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
45+ y = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
46+
4047 b . tic ( ) ;
4148 for ( i = 0 ; i < b . iterations ; i ++ ) {
42- x = ( randu ( ) * 100.0 ) - 50.0 ;
43- y = ( randu ( ) * 100.0 ) - 50.0 ;
44- h = ampbmf ( f32 ( x ) , f32 ( y ) ) ;
49+ h = ampbmf ( x [ i % x . length ] , y [ i % y . length ] ) ;
4550 if ( isnanf ( h ) ) {
4651 b . fail ( 'should not return NaN' ) ;
4752 }
@@ -57,18 +62,22 @@ bench( pkg, function benchmark( b ) {
5762
5863bench ( pkg + ':factory:alpha=1.0,beta=0.5,nonnegative=true,ints=false' , function benchmark ( b ) {
5964 var hypotf ;
65+ var opts ;
6066 var x ;
6167 var y ;
6268 var h ;
6369 var i ;
6470
65- hypotf = ampbmf . factory ( 1.0 , 0.5 , true , false ) ;
71+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.5 ) , true , false ) ;
72+ opts = {
73+ 'dtype' : 'float32'
74+ } ;
75+ x = uniform ( 100 , 0.0 , 100.0 , opts ) ;
76+ y = uniform ( 100 , 0.0 , 100.0 , opts ) ;
6677
6778 b . tic ( ) ;
6879 for ( i = 0 ; i < b . iterations ; i ++ ) {
69- x = ( randu ( ) * 100.0 ) - 0.0 ;
70- y = ( randu ( ) * 100.0 ) - 0.0 ;
71- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
80+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
7281 if ( isnanf ( h ) ) {
7382 b . fail ( 'should not return NaN' ) ;
7483 }
@@ -84,18 +93,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=true,ints=false', function b
8493
8594bench ( pkg + ':factory:alpha=1.0,beta=0.5,nonnegative=true,ints=true' , function benchmark ( b ) {
8695 var hypotf ;
96+ var opts ;
8797 var x ;
8898 var y ;
8999 var h ;
90100 var i ;
91101
92- hypotf = ampbmf . factory ( 1.0 , 0.5 , true , true ) ;
102+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.5 ) , true , true ) ;
103+ opts = {
104+ 'dtype' : 'float32'
105+ } ;
106+ x = discreteUniform ( 100 , 0 , 100 , opts ) ;
107+ y = discreteUniform ( 100 , 0 , 100 , opts ) ;
93108
94109 b . tic ( ) ;
95110 for ( i = 0 ; i < b . iterations ; i ++ ) {
96- x = ceilf ( randu ( ) * 100.0 ) - 0 ;
97- y = ceilf ( randu ( ) * 100.0 ) - 0 ;
98- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
111+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
99112 if ( isnanf ( h ) ) {
100113 b . fail ( 'should not return NaN' ) ;
101114 }
@@ -111,18 +124,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=true,ints=true', function be
111124
112125bench ( pkg + ':factory:alpha=1.0,beta=0.5,nonnegative=false,ints=false' , function benchmark ( b ) {
113126 var hypotf ;
127+ var opts ;
114128 var x ;
115129 var y ;
116130 var h ;
117131 var i ;
118132
119- hypotf = ampbmf . factory ( 1.0 , 0.5 , false , false ) ;
133+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.5 ) , false , false ) ;
134+ opts = {
135+ 'dtype' : 'float32'
136+ } ;
137+ x = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
138+ y = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
120139
121140 b . tic ( ) ;
122141 for ( i = 0 ; i < b . iterations ; i ++ ) {
123- x = ( randu ( ) * 100.0 ) - 50.0 ;
124- y = ( randu ( ) * 100.0 ) - 50.0 ;
125- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
142+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
126143 if ( isnanf ( h ) ) {
127144 b . fail ( 'should not return NaN' ) ;
128145 }
@@ -138,18 +155,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=false,ints=false', function
138155
139156bench ( pkg + ':factory:alpha=1.0,beta=0.5,nonnegative=false,ints=true' , function benchmark ( b ) {
140157 var hypotf ;
158+ var opts ;
141159 var x ;
142160 var y ;
143161 var h ;
144162 var i ;
145163
146- hypotf = ampbmf . factory ( 1.0 , 0.5 , false , true ) ;
164+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.5 ) , false , true ) ;
165+ opts = {
166+ 'dtype' : 'float32'
167+ } ;
168+ x = discreteUniform ( 100 , - 50 , 50 , opts ) ;
169+ y = discreteUniform ( 100 , - 50 , 50 , opts ) ;
147170
148171 b . tic ( ) ;
149172 for ( i = 0 ; i < b . iterations ; i ++ ) {
150- x = ceilf ( randu ( ) * 100.0 ) - 50 ;
151- y = ceilf ( randu ( ) * 100.0 ) - 50 ;
152- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
173+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
153174 if ( isnanf ( h ) ) {
154175 b . fail ( 'should not return NaN' ) ;
155176 }
@@ -165,18 +186,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=false,ints=true', function b
165186
166187bench ( pkg + ':factory:alpha=1.0,beta=0.25,nonnegative=true,ints=false' , function benchmark ( b ) {
167188 var hypotf ;
189+ var opts ;
168190 var x ;
169191 var y ;
170192 var h ;
171193 var i ;
172194
173- hypotf = ampbmf . factory ( 1.0 , 0.25 , true , false ) ;
195+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.25 ) , true , false ) ;
196+ opts = {
197+ 'dtype' : 'float32'
198+ } ;
199+ x = uniform ( 100 , 0.0 , 100.0 , opts ) ;
200+ y = uniform ( 100 , 0.0 , 100.0 , opts ) ;
174201
175202 b . tic ( ) ;
176203 for ( i = 0 ; i < b . iterations ; i ++ ) {
177- x = ( randu ( ) * 100.0 ) - 0.0 ;
178- y = ( randu ( ) * 100.0 ) - 0.0 ;
179- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
204+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
180205 if ( isnanf ( h ) ) {
181206 b . fail ( 'should not return NaN' ) ;
182207 }
@@ -192,18 +217,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=true,ints=false', function
192217
193218bench ( pkg + ':factory:alpha=1.0,beta=0.25,nonnegative=true,ints=true' , function benchmark ( b ) {
194219 var hypotf ;
220+ var opts ;
195221 var x ;
196222 var y ;
197223 var h ;
198224 var i ;
199225
200- hypotf = ampbmf . factory ( 1.0 , 0.25 , true , true ) ;
226+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.25 ) , true , true ) ;
227+ opts = {
228+ 'dtype' : 'float32'
229+ } ;
230+ x = discreteUniform ( 100 , 0 , 100 , opts ) ;
231+ y = discreteUniform ( 100 , 0 , 100 , opts ) ;
201232
202233 b . tic ( ) ;
203234 for ( i = 0 ; i < b . iterations ; i ++ ) {
204- x = ceilf ( randu ( ) * 100.0 ) - 0 ;
205- y = ceilf ( randu ( ) * 100.0 ) - 0 ;
206- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
235+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
207236 if ( isnanf ( h ) ) {
208237 b . fail ( 'should not return NaN' ) ;
209238 }
@@ -219,18 +248,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=true,ints=true', function b
219248
220249bench ( pkg + ':factory:alpha=1.0,beta=0.25,nonnegative=false,ints=false' , function benchmark ( b ) {
221250 var hypotf ;
251+ var opts ;
222252 var x ;
223253 var y ;
224254 var h ;
225255 var i ;
226256
227- hypotf = ampbmf . factory ( 1.0 , 0.25 , false , false ) ;
257+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.25 ) , false , false ) ;
258+ opts = {
259+ 'dtype' : 'float32'
260+ } ;
261+ x = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
262+ y = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
228263
229264 b . tic ( ) ;
230265 for ( i = 0 ; i < b . iterations ; i ++ ) {
231- x = ( randu ( ) * 100.0 ) - 50.0 ;
232- y = ( randu ( ) * 100.0 ) - 50.0 ;
233- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
266+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
234267 if ( isnanf ( h ) ) {
235268 b . fail ( 'should not return NaN' ) ;
236269 }
@@ -246,18 +279,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=false,ints=false', function
246279
247280bench ( pkg + ':factory:alpha=1.0,beta=0.25,nonnegative=false,ints=true' , function benchmark ( b ) {
248281 var hypotf ;
282+ var opts ;
249283 var x ;
250284 var y ;
251285 var h ;
252286 var i ;
253287
254- hypotf = ampbmf . factory ( 1.0 , 0.25 , false , true ) ;
288+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( 0.25 ) , false , true ) ;
289+ opts = {
290+ 'dtype' : 'float32'
291+ } ;
292+ x = discreteUniform ( 100 , - 50 , 50 , opts ) ;
293+ y = discreteUniform ( 100 , - 50 , 50 , opts ) ;
255294
256295 b . tic ( ) ;
257296 for ( i = 0 ; i < b . iterations ; i ++ ) {
258- x = ceilf ( randu ( ) * 100.0 ) - 50 ;
259- y = ceilf ( randu ( ) * 100.0 ) - 50 ;
260- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
297+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
261298 if ( isnanf ( h ) ) {
262299 b . fail ( 'should not return NaN' ) ;
263300 }
@@ -273,18 +310,22 @@ bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=false,ints=true', function
273310
274311bench ( pkg + ':factory:alpha=1.0,beta=3/8,nonnegative=true,ints=false' , function benchmark ( b ) {
275312 var hypotf ;
313+ var opts ;
276314 var x ;
277315 var y ;
278316 var h ;
279317 var i ;
280318
281- hypotf = ampbmf . factory ( 1.0 , 3.0 / 8.0 , true , false ) ;
319+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( f32 ( 3.0 ) / f32 ( 8.0 ) ) , true , false ) ;
320+ opts = {
321+ 'dtype' : 'float32'
322+ } ;
323+ x = uniform ( 100 , 0.0 , 100.0 , opts ) ;
324+ y = uniform ( 100 , 0.0 , 100.0 , opts ) ;
282325
283326 b . tic ( ) ;
284327 for ( i = 0 ; i < b . iterations ; i ++ ) {
285- x = ( randu ( ) * 100.0 ) - 0.0 ;
286- y = ( randu ( ) * 100.0 ) - 0.0 ;
287- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
328+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
288329 if ( isnanf ( h ) ) {
289330 b . fail ( 'should not return NaN' ) ;
290331 }
@@ -300,18 +341,22 @@ bench( pkg+':factory:alpha=1.0,beta=3/8,nonnegative=true,ints=false', function b
300341
301342bench ( pkg + ':factory:alpha=1.0,beta=3/8,nonnegative=true,ints=true' , function benchmark ( b ) {
302343 var hypotf ;
344+ var opts ;
303345 var x ;
304346 var y ;
305347 var h ;
306348 var i ;
307349
308- hypotf = ampbmf . factory ( 1.0 , 3.0 / 8.0 , true , true ) ;
350+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( f32 ( 3.0 ) / f32 ( 8.0 ) ) , true , true ) ;
351+ opts = {
352+ 'dtype' : 'float32'
353+ } ;
354+ x = discreteUniform ( 100 , 0 , 100 , opts ) ;
355+ y = discreteUniform ( 100 , 0 , 100 , opts ) ;
309356
310357 b . tic ( ) ;
311358 for ( i = 0 ; i < b . iterations ; i ++ ) {
312- x = ceilf ( randu ( ) * 100.0 ) - 0 ;
313- y = ceilf ( randu ( ) * 100.0 ) - 0 ;
314- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
359+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
315360 if ( isnanf ( h ) ) {
316361 b . fail ( 'should not return NaN' ) ;
317362 }
@@ -327,18 +372,22 @@ bench( pkg+':factory:alpha=1.0,beta=3/8,nonnegative=true,ints=true', function be
327372
328373bench ( pkg + ':factory:alpha=1.0,beta=3/8,nonnegative=false,ints=false' , function benchmark ( b ) {
329374 var hypotf ;
375+ var opts ;
330376 var x ;
331377 var y ;
332378 var h ;
333379 var i ;
334380
335- hypotf = ampbmf . factory ( 1.0 , 3.0 / 8.0 , false , false ) ;
381+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( f32 ( 3.0 ) / f32 ( 8.0 ) ) , false , false ) ;
382+ opts = {
383+ 'dtype' : 'float32'
384+ } ;
385+ x = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
386+ y = uniform ( 100 , - 50.0 , 50.0 , opts ) ;
336387
337388 b . tic ( ) ;
338389 for ( i = 0 ; i < b . iterations ; i ++ ) {
339- x = ( randu ( ) * 100.0 ) - 50.0 ;
340- y = ( randu ( ) * 100.0 ) - 50.0 ;
341- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
390+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
342391 if ( isnanf ( h ) ) {
343392 b . fail ( 'should not return NaN' ) ;
344393 }
@@ -354,18 +403,22 @@ bench( pkg+':factory:alpha=1.0,beta=3/8,nonnegative=false,ints=false', function
354403
355404bench ( pkg + ':factory:alpha=1.0,beta=3/8,nonnegative=false,ints=true' , function benchmark ( b ) {
356405 var hypotf ;
406+ var opts ;
357407 var x ;
358408 var y ;
359409 var h ;
360410 var i ;
361411
362- hypotf = ampbmf . factory ( 1.0 , 3.0 / 8.0 , false , true ) ;
412+ hypotf = ampbmf . factory ( f32 ( 1.0 ) , f32 ( f32 ( 3.0 ) / f32 ( 8.0 ) ) , false , true ) ;
413+ opts = {
414+ 'dtype' : 'float32'
415+ } ;
416+ x = discreteUniform ( 100 , - 50 , 50 , opts ) ;
417+ y = discreteUniform ( 100 , - 50 , 50 , opts ) ;
363418
364419 b . tic ( ) ;
365420 for ( i = 0 ; i < b . iterations ; i ++ ) {
366- x = ceilf ( randu ( ) * 100.0 ) - 50 ;
367- y = ceilf ( randu ( ) * 100.0 ) - 50 ;
368- h = hypotf ( f32 ( x ) , f32 ( y ) ) ;
421+ h = hypotf ( x [ i % x . length ] , y [ i % y . length ] ) ;
369422 if ( isnanf ( h ) ) {
370423 b . fail ( 'should not return NaN' ) ;
371424 }
0 commit comments