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 ' ) ;
25+ var format = require ( '@stdlib/string/format ' ) ;
2626var pkg = require ( './../package.json' ) . name ;
2727var imul = require ( './../lib' ) ;
2828var polyfill = require ( './../lib/polyfill.js' ) ;
@@ -35,59 +35,68 @@ bench( pkg, function benchmark( b ) {
3535 var y ;
3636 var i ;
3737
38+ x = discreteUniform ( 100 , 0 , 10 , {
39+ 'dtype' : 'int32'
40+ } ) ;
41+
3842 b . tic ( ) ;
3943 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' ) ;
44+ y = imul ( x [ i % x . length ] , 10 ) ;
45+ if ( y > 100 ) {
46+ b . fail ( 'unexpected result' ) ;
4447 }
4548 }
4649 b . toc ( ) ;
47- if ( isnan ( y ) ) {
48- b . fail ( 'should not return NaN ' ) ;
50+ if ( y > 100 ) {
51+ b . fail ( 'unexpected result ' ) ;
4952 }
5053 b . pass ( 'benchmark finished' ) ;
5154 b . end ( ) ;
5255} ) ;
5356
54- bench ( pkg + ' ::polyfill', function benchmark ( b ) {
57+ bench ( format ( '%s ::polyfill', pkg ) , function benchmark ( b ) {
5558 var x ;
5659 var y ;
5760 var i ;
5861
62+ x = discreteUniform ( 100 , 0 , 10 , {
63+ 'dtype' : 'int32'
64+ } ) ;
65+
5966 b . tic ( ) ;
6067 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' ) ;
68+ y = polyfill ( x [ i % x . length ] , 10 ) ;
69+ if ( y > 100 ) {
70+ b . fail ( 'unexpected result' ) ;
6571 }
6672 }
6773 b . toc ( ) ;
68- if ( isnan ( y ) ) {
69- b . fail ( 'should not return NaN ' ) ;
74+ if ( y > 100 ) {
75+ b . fail ( 'unexpected result ' ) ;
7076 }
7177 b . pass ( 'benchmark finished' ) ;
7278 b . end ( ) ;
7379} ) ;
7480
75- bench ( pkg + '::naive_multiplication' , function benchmark ( b ) {
81+ bench ( format ( '%s::inline' , pkg ) , function benchmark ( b ) {
7682 var x ;
7783 var y ;
7884 var i ;
7985
86+ x = discreteUniform ( 100 , 0 , 10 , {
87+ 'dtype' : 'int32'
88+ } ) ;
89+
8090 b . tic ( ) ;
8191 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' ) ;
92+ y = ( ( x [ i % x . length ] ) * 5 ) | 0 ;
93+ if ( y > 100 ) {
94+ b . fail ( 'unexpected result' ) ;
8695 }
8796 }
8897 b . toc ( ) ;
89- if ( isnan ( y ) ) {
90- b . fail ( 'should not return NaN ' ) ;
98+ if ( y > 100 ) {
99+ b . fail ( 'unexpected result ' ) ;
91100 }
92101 b . pass ( 'benchmark finished' ) ;
93102 b . end ( ) ;
0 commit comments