Skip to content

Commit

Permalink
feat: benchmarks with precomputation
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush0325 committed Dec 8, 2024
1 parent b5432f0 commit e24d264
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var randu = require( '@stdlib/random/array/discrete-uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var diracDeltaf = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = randu( 100, -50, 50 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 100.0 ) - 50.0;
y = diracDeltaf( x );
y = diracDeltaf( x[ i % x.length ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var randu = require( '@stdlib/random/array/discrete-uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = randu( 100, -50, 50 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 50.0;
y = diracDeltaf( x );
y = diracDeltaf( x[ i % x.length ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@ static double rand_float( void ) {
*/
static double benchmark( void ) {
double elapsed;
float x;
float x[ 100 ];
float y;
double t;
int i;

for ( i = 0; i < 100 ; i++ ) {
x[ i ] = ( 100.0f * rand_float() ) - 50.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0f * rand_float() ) - 50.0f;
y = stdlib_base_dirac_deltaf( x );
y = stdlib_base_dirac_deltaf( x[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down

0 comments on commit e24d264

Please sign in to comment.