Skip to content

Commit 01f41d2

Browse files
author
aayush0325
committed
feat: updated benchmarks with precomputation
1 parent f27a204 commit 01f41d2

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

lib/node_modules/@stdlib/math/base/special/nonfibonaccif/benchmark/benchmark.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
25-
var floorf = require( '@stdlib/math/base/special/floorf' );
24+
var randu = require( '@stdlib/random/array/discrete-uniform' );
2625
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2726
var pkg = require( './../package.json' ).name;
2827
var nonfibonaccif = require( './../lib' );
@@ -35,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3534
var y;
3635
var i;
3736

37+
x = randu( 100, 1, 100 );
38+
3839
b.tic();
3940
for ( i = 0; i < b.iterations; i++ ) {
40-
x = floorf( (randu()*100.0) + 1.0 );
41-
y = nonfibonaccif( x );
41+
y = nonfibonaccif( x[ i % 100 ] );
4242
if ( isnanf( y ) ) {
4343
b.fail( 'should not return NaN' );
4444
}

lib/node_modules/@stdlib/math/base/special/nonfibonaccif/benchmark/benchmark.native.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
// MODULES //
2222

2323
var resolve = require( 'path' ).resolve;
24-
var floorf = require( '@stdlib/math/base/special/floorf' );
2524
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26-
var randu = require( '@stdlib/random/base/randu' );
25+
var randu = require( '@stdlib/random/array/discrete-uniform' );
2726
var tryRequire = require( '@stdlib/utils/try-require' );
2827
var bench = require( '@stdlib/bench' );
2928
var pkg = require( './../package.json' ).name;
@@ -44,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4443
var y;
4544
var i;
4645

46+
x = randu( 100, 1, 100 );
47+
4748
b.tic();
4849
for ( i = 0; i < b.iterations; i++ ) {
49-
x = floorf( (randu()*100.0) + 1.0 );
50-
y = nonfibonaccif( x );
50+
y = nonfibonaccif( x[ i % 100 ] );
5151
if ( isnanf( y ) ) {
5252
b.fail( 'should not return NaN' );
5353
}

lib/node_modules/@stdlib/math/base/special/nonfibonaccif/benchmark/c/native/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ static double benchmark( void ) {
9292
double elapsed;
9393
double t;
9494
float y;
95-
int x;
95+
int x[ 100 ];
9696
int i;
9797

98+
for ( i = 0; i < 100; i++ ) {
99+
x[ i ] = (int)floorf( ( 100.0f * rand_float() ) + 1.0f );
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = (int)floorf( ( 100.0f * rand_float() ) + 1.0f );
101-
y = stdlib_base_nonfibonaccif( x );
104+
y = stdlib_base_nonfibonaccif( x[ i % 100 ] );
102105
if ( y < 0 ) {
103106
printf( "should return a nonnegative integer\n" );
104107
break;

0 commit comments

Comments
 (0)