2121// MODULES //
2222
2323var bench = require ( '@stdlib/bench' ) ;
24- var minstd = require ( '@stdlib/random/base/minstd' ) ;
25- var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
24+ var discreteUniform = require ( '@stdlib/random/array/discrete-uniform' ) ;
2625var pkg = require ( './../package.json' ) . name ;
2726var imul = require ( './../lib' ) ;
2827var polyfill = require ( './../lib/polyfill.js' ) ;
@@ -35,17 +34,20 @@ bench( pkg, function benchmark( b ) {
3534 var y ;
3635 var i ;
3736
37+ x = discreteUniform ( 100 , 0 , 10 , {
38+ 'dtype' : 'int32'
39+ } ) ;
40+
3841 b . tic ( ) ;
3942 for ( i = 0 ; i < b . iterations ; i ++ ) {
40- x = minstd ( ) ;
41- y = imul ( x | 0 , x | 0 ) ;
42- if ( isnan ( y ) ) {
43- b . fail ( 'should not return NaN' ) ;
43+ y = imul ( x [ i % x . length ] , 10 ) ;
44+ if ( y > 100 ) {
45+ b . fail ( 'unexpected result' ) ;
4446 }
4547 }
4648 b . toc ( ) ;
47- if ( isnan ( y ) ) {
48- b . fail ( 'should not return NaN ' ) ;
49+ if ( y > 100 ) {
50+ b . fail ( 'unexpected result ' ) ;
4951 }
5052 b . pass ( 'benchmark finished' ) ;
5153 b . end ( ) ;
@@ -56,38 +58,44 @@ bench( pkg+'::polyfill', function benchmark( b ) {
5658 var y ;
5759 var i ;
5860
61+ x = discreteUniform ( 100 , 0 , 10 , {
62+ 'dtype' : 'int32'
63+ } ) ;
64+
5965 b . tic ( ) ;
6066 for ( i = 0 ; i < b . iterations ; i ++ ) {
61- x = minstd ( ) ;
62- y = polyfill ( x | 0 , x | 0 ) ;
63- if ( isnan ( y ) ) {
64- b . fail ( 'should not return NaN' ) ;
67+ y = polyfill ( x [ i % x . length ] , 10 ) ;
68+ if ( y > 100 ) {
69+ b . fail ( 'unexpected result' ) ;
6570 }
6671 }
6772 b . toc ( ) ;
68- if ( isnan ( y ) ) {
69- b . fail ( 'should not return NaN ' ) ;
73+ if ( y > 100 ) {
74+ b . fail ( 'unexpected result ' ) ;
7075 }
7176 b . pass ( 'benchmark finished' ) ;
7277 b . end ( ) ;
7378} ) ;
7479
75- bench ( pkg + '::naive_multiplication ' , function benchmark ( b ) {
80+ bench ( pkg + '::inline ' , function benchmark ( b ) {
7681 var x ;
7782 var y ;
7883 var i ;
7984
85+ x = discreteUniform ( 100 , 0 , 10 , {
86+ 'dtype' : 'int32'
87+ } ) ;
88+
8089 b . tic ( ) ;
8190 for ( i = 0 ; i < b . iterations ; i ++ ) {
82- x = minstd ( ) ;
83- y = ( x | 0 ) * ( x | 0 ) ;
84- if ( isnan ( y ) ) {
85- b . fail ( 'should not return NaN' ) ;
91+ y = ( ( x [ i % x . length ] ) * 5 ) | 0 ;
92+ if ( y > 100 ) {
93+ b . fail ( 'unexpected result' ) ;
8694 }
8795 }
8896 b . toc ( ) ;
89- if ( isnan ( y ) ) {
90- b . fail ( 'should not return NaN ' ) ;
97+ if ( y > 100 ) {
98+ b . fail ( 'unexpected result ' ) ;
9199 }
92100 b . pass ( 'benchmark finished' ) ;
93101 b . end ( ) ;
0 commit comments