Skip to content

Commit af92abf

Browse files
committed
bench: update random value generation
1 parent 60310a4 commit af92abf

File tree

12 files changed

+95
-65
lines changed

12 files changed

+95
-65
lines changed

lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.js

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

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var floor = require( '@stdlib/math/base/special/floor' );
26+
var zeros = require( '@stdlib/array/base/zeros' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var fibonacci = require( '@stdlib/math/base/special/fibonacci' );
2829
var pkg = require( './../package.json' ).name;
@@ -37,14 +38,16 @@ bench( pkg, function benchmark( b ) {
3738
var y;
3839
var i;
3940

40-
FN = new Array( 76 );
41+
FN = zeros( 76 );
4142
for ( i = 3; i < 79; i++ ) {
4243
FN[ i ] = fibonacci( i );
4344
}
45+
46+
x = floor( uniform( 100, 3.0, 78.0 ) );
47+
4448
b.tic();
4549
for ( i = 0; i < b.iterations; i++ ) {
46-
x = floor( (randu()*75.0) + 3.0 );
47-
y = fibonacciIndex( FN[ x ] );
50+
y = fibonacciIndex( FN[ x[ i%x.length ] ] );
4851
if ( isnan( y ) ) {
4952
b.fail( 'should not return NaN' );
5053
}

lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.native.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var randu = require( '@stdlib/random/base/randu' );
2626
var floor = require( '@stdlib/math/base/special/floor' );
27+
var zeros = require( '@stdlib/array/base/zeros' );
2728
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2829
var fibonacci = require( '@stdlib/math/base/special/fibonacci' );
2930
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -46,14 +47,16 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4647
var y;
4748
var i;
4849

49-
FN = new Array( 76 );
50+
FN = zeros( 76 );
5051
for ( i = 3; i < 79; i++ ) {
5152
FN[ i ] = fibonacci( i );
5253
}
54+
55+
x = floor( uniform( 100, 3.0, 78.0 ) );
56+
5357
b.tic();
5458
for ( i = 0; i < b.iterations; i++ ) {
55-
x = floor( ( randu() * 75.0 ) + 3.0 );
56-
y = fibonacciIndex( FN[ x ] );
59+
y = fibonacciIndex( FN[ x[ i%x.length ] ] );
5760
if ( isnan( y ) ) {
5861
b.fail( 'should not return NaN' );
5962
}

lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ int fibonacci_index( int F ) {
102102
static double benchmark( void ) {
103103
double elapsed;
104104
double t;
105-
int x;
105+
int x[ 100 ];
106106
int y;
107107
int i;
108108

109+
for ( i = 0; i < 100; i++ ) {
110+
x[ i ] = (int)floor( (100000.0*rand_double()) + 2.0 );
111+
}
112+
109113
t = tic();
110114
for ( i = 0; i < ITERATIONS; i++ ) {
111115
// note: using actual Fibonacci numbers is not important
112-
x = (int)floor( (100000.0*rand_double()) + 2.0 );
113-
y = fibonacci_index( x );
116+
y = fibonacci_index( x[ i%100 ] );
114117
if ( y < 0 ) {
115118
printf( "should return a nonnegative integer\n" );
116119
break;

lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/native/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double x;
94+
double x[ 100 ];
9595
double y;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = (int)floor( ( 75.0 * rand_double() ) + 3.0 );
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = (int)floor( ( 75.0 * rand_double() ) + 3.0 );
102-
y = stdlib_base_fibonacci_index( x );
105+
y = stdlib_base_fibonacci_index( x[ i%100 ] );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,32 @@ tape( 'main export is a function', function test( t ) {
3737

3838
tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
3939
var n = fibonacciIndex( NaN );
40-
t.strictEqual( isnan( n ), true, 'returns NaN when provided a NaN' );
40+
t.strictEqual( isnan( n ), true, 'returns expected value when provided a NaN' );
4141
t.end();
4242
});
4343

4444
tape( 'if provided `+infinity`, the function returns `NaN`', function test( t ) {
4545
var n = fibonacciIndex( PINF );
46-
t.strictEqual( isnan( n ), true, 'returns NaN' );
46+
t.strictEqual( isnan( n ), true, 'returns expected value' );
4747
t.end();
4848
});
4949

5050
tape( 'if provided a number less than or equal to 1, the function returns `NaN`', function test( t ) {
5151
var n;
5252
var i;
5353

54-
t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns NaN' );
54+
t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns expected value' );
5555

5656
for ( i = 1; i > -100; i-- ) {
5757
n = fibonacciIndex( i );
58-
t.strictEqual( isnan( n ), true, 'returns NaN when provided ' + i );
58+
t.strictEqual( isnan( n ), true, 'returns expected value when provided ' + i );
5959
}
6060
t.end();
6161
});
6262

6363
tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) {
6464
var n = fibonacciIndex( 3.14 );
65-
t.strictEqual( isnan( n ), true, 'returns NaN' );
65+
t.strictEqual( isnan( n ), true, 'returns expected value' );
6666
t.end();
6767
});
6868

lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.native.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,32 @@ tape( 'main export is a function', opts, function test( t ) {
4646

4747
tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) {
4848
var n = fibonacciIndex( NaN );
49-
t.strictEqual( isnan( n ), true, 'returns NaN when provided a NaN' );
49+
t.strictEqual( isnan( n ), true, 'returns expected value when provided a NaN' );
5050
t.end();
5151
});
5252

5353
tape( 'if provided `+infinity`, the function returns `NaN`', opts, function test( t ) {
5454
var n = fibonacciIndex( PINF );
55-
t.strictEqual( isnan( n ), true, 'returns NaN' );
55+
t.strictEqual( isnan( n ), true, 'returns expected value' );
5656
t.end();
5757
});
5858

5959
tape( 'if provided a number less than or equal to 1, the function returns `NaN`', opts, function test( t ) {
6060
var n;
6161
var i;
6262

63-
t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns NaN' );
63+
t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns expected value' );
6464

6565
for ( i = 1; i > -100; i-- ) {
6666
n = fibonacciIndex( i );
67-
t.strictEqual( isnan( n ), true, 'returns NaN when provided ' + i );
67+
t.strictEqual( isnan( n ), true, 'returns expected value when provided ' + i );
6868
}
6969
t.end();
7070
});
7171

7272
tape( 'if provided a non-integer, the function returns `NaN`', opts, function test( t ) {
7373
var n = fibonacciIndex( 3.14 );
74-
t.strictEqual( isnan( n ), true, 'returns NaN' );
74+
t.strictEqual( isnan( n ), true, 'returns expected value' );
7575
t.end();
7676
});
7777

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

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var floor = require( '@stdlib/math/base/special/floor' );
2626
var round = require( '@stdlib/math/base/special/round' );
2727
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2828
var pow = require( '@stdlib/math/base/special/pow' );
29+
var zeros = require( '@stdlib/array/base/zeros' );
2930
var isnan = require( '@stdlib/math/base/assert/is-nan' );
3031
var PHI = require( '@stdlib/constants/float64/phi' );
3132
var pkg = require( './../package.json' ).name;
@@ -45,10 +46,11 @@ bench( pkg, function benchmark( b ) {
4546
var y;
4647
var i;
4748

49+
x = floor( uniform( 100, 0.0, 79.0 ) );
50+
4851
b.tic();
4952
for ( i = 0; i < b.iterations; i++ ) {
50-
x = floor( randu()*79.0 );
51-
y = fibonacci( x );
53+
y = fibonacci( x[ i%x.length ] );
5254
if ( isnan( y ) ) {
5355
b.fail( 'should not return NaN' );
5456
}
@@ -70,10 +72,11 @@ bench( pkg+'::analytic', function benchmark( b ) {
7072
return round( pow( PHI, n ) / SQRT_5 );
7173
}
7274

75+
x = floor( uniform( 100, 0.0, 79.0 ) );
76+
7377
b.tic();
7478
for ( i = 0; i < b.iterations; i++ ) {
75-
x = floor( randu()*79.0 );
76-
y = fibonacci( x );
79+
y = fibonacci( x[ i%x.length ] );
7780
if ( isnan( y ) ) {
7881
b.fail( 'should not return NaN' );
7982
}
@@ -91,10 +94,11 @@ bench( pkg+'::table', function benchmark( b ) {
9194
var y;
9295
var i;
9396

97+
x = floor( uniform( 100, 0.0, 79.0 ) );
98+
9499
b.tic();
95100
for ( i = 0; i < b.iterations; i++ ) {
96-
x = floor( randu()*79.0 );
97-
y = FIBONACCI[ x ];
101+
y = FIBONACCI[ x[ i%x.length ] ];
98102
if ( isnan( y ) ) {
99103
b.fail( 'should not return NaN' );
100104
}
@@ -119,10 +123,11 @@ bench( pkg+'::naive_recursion', function benchmark( b ) {
119123
return fibonacci( n-1 ) + fibonacci( n-2 );
120124
}
121125

126+
x = floor( uniform( 100, 0.0, 40.0 ) ); // limit upper bound
127+
122128
b.tic();
123129
for ( i = 0; i < b.iterations; i++ ) {
124-
x = floor( randu()*40.0 ); // limit upper bound
125-
y = fibonacci( x );
130+
y = fibonacci( x[ i%x.length ] );
126131
if ( isnan( y ) ) {
127132
b.fail( 'should not return NaN' );
128133
}
@@ -142,7 +147,7 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) {
142147
var y;
143148
var i;
144149

145-
arr = new Array( 79 );
150+
arr = zeros( 79 );
146151
arr[ 0 ] = 0;
147152
arr[ 1 ] = 1;
148153
arr[ 2 ] = 1;
@@ -156,10 +161,11 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) {
156161
return arr[ n ];
157162
}
158163

164+
x = floor( uniform( 100, 0.0, 40.0 ) ); // limit upper bound
165+
159166
b.tic();
160167
for ( i = 0; i < b.iterations; i++ ) {
161-
x = floor( randu()*40.0 ); // limit upper bound
162-
y = fibonacci( x );
168+
y = fibonacci( x[ i%x.length ] );
163169
if ( isnan( y ) ) {
164170
b.fail( 'should not return NaN' );
165171
}
@@ -181,7 +187,7 @@ bench( pkg+'::naive_iterative', function benchmark( b ) {
181187
var arr;
182188
var i;
183189

184-
arr = new Array( n+1 );
190+
arr = zeros( n+1 );
185191
arr[ 0 ] = 0;
186192
arr[ 1 ] = 1;
187193
arr[ 2 ] = 1;
@@ -191,10 +197,11 @@ bench( pkg+'::naive_iterative', function benchmark( b ) {
191197
return arr[ n ];
192198
}
193199

200+
x = floor( uniform( 100, 0.0, 79.0 ) ); // limit upper bound
201+
194202
b.tic();
195203
for ( i = 0; i < b.iterations; i++ ) {
196-
x = floor( randu()*79.0 );
197-
y = fibonacci( x );
204+
y = fibonacci( x[ i%x.length ] );
198205
if ( isnan( y ) ) {
199206
b.fail( 'should not return NaN' );
200207
}
@@ -228,10 +235,11 @@ bench( pkg+'::iterative', function benchmark( b ) {
228235
return b;
229236
}
230237

238+
x = floor( uniform( 100, 0.0, 79.0 ) );
239+
231240
b.tic();
232241
for ( i = 0; i < b.iterations; i++ ) {
233-
x = floor( randu()*79.0 );
234-
y = fibonacci( x );
242+
y = fibonacci( x[ i%x.length ] );
235243
if ( isnan( y ) ) {
236244
b.fail( 'should not return NaN' );
237245
}
@@ -251,7 +259,7 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) {
251259
var y;
252260
var i;
253261

254-
arr = new Array( 79 );
262+
arr = zeros( 79 );
255263
arr[ 0 ] = 0;
256264
arr[ 1 ] = 1;
257265
arr[ 2 ] = 1;
@@ -268,10 +276,11 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) {
268276
return arr[ n ];
269277
}
270278

279+
x = floor( uniform( 100, 0.0, 79.0 ) );
280+
271281
b.tic();
272282
for ( i = 0; i < b.iterations; i++ ) {
273-
x = floor( randu()*79.0 );
274-
y = fibonacci( x );
283+
y = fibonacci( x[ i%x.length ] );
275284
if ( isnan( y ) ) {
276285
b.fail( 'should not return NaN' );
277286
}
@@ -314,10 +323,11 @@ bench( pkg+'::iterative_doubling', function benchmark( b ) {
314323
return a + b;
315324
}
316325

326+
x = floor( uniform( 100, 0.0, 79.0 ) );
327+
317328
b.tic();
318329
for ( i = 0; i < b.iterations; i++ ) {
319-
x = floor( randu()*79.0 );
320-
y = fibonacci( x );
330+
y = fibonacci( x[ i%x.length ] );
321331
if ( isnan( y ) ) {
322332
b.fail( 'should not return NaN' );
323333
}
@@ -337,7 +347,7 @@ bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) {
337347
var y;
338348
var i;
339349

340-
arr = new Array( 79 );
350+
arr = zeros( 79 );
341351
arr[ 0 ] = 0;
342352
arr[ 1 ] = 1;
343353
arr[ 2 ] = 1;
@@ -377,10 +387,11 @@ bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) {
377387
return a + b;
378388
}
379389

390+
x = floor( uniform( 100, 0.0, 79.0 ) );
391+
380392
b.tic();
381393
for ( i = 0; i < b.iterations; i++ ) {
382-
x = floor( randu()*79.0 );
383-
y = fibonacci( x );
394+
y = fibonacci( x[ i%x.length ] );
384395
if ( isnan( y ) ) {
385396
b.fail( 'should not return NaN' );
386397
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var floor = require( '@stdlib/math/base/special/floor' );
2727
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -44,10 +44,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var y;
4545
var i;
4646

47+
x = floor( uniform( 100, 0.0, 79.0 ) );
48+
4749
b.tic();
4850
for ( i = 0; i < b.iterations; i++ ) {
49-
x = floor( randu()*79.0 );
50-
y = fibonacci( x );
51+
y = fibonacci( x[ i%x.length ] );
5152
if ( isnan( y ) ) {
5253
b.fail( 'should not return NaN' );
5354
}

0 commit comments

Comments
 (0)