Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var minstd = require( '@stdlib/random/base/minstd' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var imul = require( './../lib' );
var polyfill = require( './../lib/polyfill.js' );
Expand All @@ -35,59 +35,68 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = discreteUniform( 100, 0, 10, {
'dtype': 'int32'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = minstd();
y = imul( x|0, x|0 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
y = imul( x[ i%x.length ], 10 );
if ( y > 100 ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
if ( y > 100 ) {
b.fail( 'unexpected result' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::polyfill', function benchmark( b ) {
bench( format( '%s::polyfill', pkg ), function benchmark( b ) {
var x;
var y;
var i;

x = discreteUniform( 100, 0, 10, {
'dtype': 'int32'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = minstd();
y = polyfill( x|0, x|0 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
y = polyfill( x[ i%x.length ], 10 );
if ( y > 100 ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
if ( y > 100 ) {
b.fail( 'unexpected result' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::naive_multiplication', function benchmark( b ) {
bench( format( '%s::inline', pkg ), function benchmark( b ) {
var x;
var y;
var i;

x = discreteUniform( 100, 0, 10, {
'dtype': 'int32'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = minstd();
y = ( x|0 ) * ( x|0 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
y = ( ( x[ i%x.length ] ) * 5 ) | 0;
if ( y > 100 ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
if ( y > 100 ) {
b.fail( 'unexpected result' );
}
b.pass( 'benchmark finished' );
b.end();
Expand Down