Skip to content

Commit

Permalink
bench: add benchmark using nested arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Aug 26, 2023
1 parent 8735d98 commit 51c9286
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var filled2dBy = require( '@stdlib/array/base/filled2d-by' );
var unary2d = require( '@stdlib/array/base/unary2d' );
var zeros2d = require( '@stdlib/array/base/zeros2d' );
var array = require( '@stdlib/ndarray/array' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var base = require( '@stdlib/math/base/special/abs' );
var abs = require( '@stdlib/math/special/abs' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -41,7 +44,7 @@ var opts = {

// MAIN //

bench( pkg+'::stdlib:math/special/abs:value=matrix,dtype=generic,size=100,shape=(10,10)', opts, function benchmark( b ) {
bench( pkg+'::stdlib:math/special/abs:value=ndarray,dtype=generic,size=100,shape=(10,10)', opts, function benchmark( b ) {
var x;
var y;
var i;
Expand All @@ -65,6 +68,31 @@ bench( pkg+'::stdlib:math/special/abs:value=matrix,dtype=generic,size=100,shape=
b.end();
});

bench( pkg+'::stdlib:math/special/abs:value=nested_array,dtype=generic,size=100,shape=(10,10)', opts, function benchmark( b ) {
var sh;
var x;
var y;
var i;

sh = [ 10, 10 ];
x = filled2dBy( sh, uniform( -100.0, 100.0 ) );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = zeros2d( sh );
unary2d( [ x, y ], sh, base );
if ( isnan( y[ 0 ][ 0 ] ) || isnan( y[ 9 ][ 9 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y[ 1 ][ 1 ] ) || isnan( y[ 8 ][ 8 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::mathjs:abs:value=matrix,dtype=generic,size=100,shape=(10,10)', opts, function benchmark( b ) {
var x;
var y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var opts = {

// MAIN //

bench( pkg+'::stdlib:math/special/abs:value=matrix,dtype=generic,size=100,shape=(4,5,5)', opts, function benchmark( b ) {
bench( pkg+'::stdlib:math/special/abs:value=ndarray,dtype=generic,size=100,shape=(4,5,5)', opts, function benchmark( b ) {
var x;
var y;
var i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var opts = {

// MAIN //

bench( pkg+'::stdlib:math/special/abs:value=matrix,dtype=generic,size=100,shape=(2,5,2,5)', opts, function benchmark( b ) {
bench( pkg+'::stdlib:math/special/abs:value=ndarray,dtype=generic,size=100,shape=(2,5,2,5)', opts, function benchmark( b ) {
var x;
var y;
var i;
Expand Down

0 comments on commit 51c9286

Please sign in to comment.