Skip to content

Commit 65f0948

Browse files
authored
bench: update random value generation
PR-URL: #6691 Reviewed-by: Philipp Burckhardt <[email protected]> Signed-off-by: Harsh <[email protected]>
1 parent 4d0f11a commit 65f0948

File tree

10 files changed

+52
-36
lines changed

10 files changed

+52
-36
lines changed

lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var pkg = require( './../package.json' ).name;
2727
var isPositiveZerof = require( './../lib' );
@@ -30,14 +30,19 @@ var isPositiveZerof = require( './../lib' );
3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33+
var opts;
3334
var x;
3435
var y;
3536
var i;
3637

38+
opts = {
39+
'dtype': 'float32'
40+
};
41+
x = uniform( 100, -50.0, 50.0, opts );
42+
3743
b.tic();
3844
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*100.0 ) - 50.0;
40-
y = isPositiveZerof( x );
45+
y = isPositiveZerof( x[ i%x.length ] );
4146
if ( typeof y !== 'boolean' ) {
4247
b.fail( 'should return a boolean' );
4348
}

lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/benchmark.native.js

Lines changed: 8 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -39,14 +39,19 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var opts;
4243
var x;
4344
var y;
4445
var i;
4546

47+
opts = {
48+
'dtype': 'float32'
49+
};
50+
x = uniform( 100, -50.0, 50.0, opts );
51+
4652
b.tic();
4753
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*100.0 ) - 50.0;
49-
y = isPositiveZerof( x );
54+
y = isPositiveZerof( x[ i%x.length ] );
5055
if ( typeof y !== 'boolean' ) {
5156
b.fail( 'should return a boolean' );
5257
}

lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,18 @@ bool is_positive_zerof( float x ) {
101101
*/
102102
static double benchmark( void ) {
103103
double elapsed;
104+
float x[ 100 ];
104105
double t;
105-
float x;
106106
bool y;
107107
int i;
108108

109+
for ( i = 0; i < 100; i++ ) {
110+
x[ i ] = ( 100.0f*rand_float() ) - 50.0f;
111+
}
112+
109113
t = tic();
110114
for ( i = 0; i < ITERATIONS; i++ ) {
111-
x = ( 100.0f*rand_float() ) - 50.0f;
112-
y = is_positive_zerof( x );
115+
y = is_positive_zerof( x[ i%100 ] );
113116
if ( y != true && y != false ) {
114117
printf( "should return true or false\n" );
115118
break;

lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/benchmark/c/native/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,18 @@ static float rand_float( void ) {
9292
*/
9393
static double benchmark( void ) {
9494
double elapsed;
95+
float x[ 100 ];
9596
double t;
96-
float x;
9797
bool b;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = (rand_float()*100.0f) - 50.0f;
102+
}
103+
100104
t = tic();
101105
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = (rand_float()*100.0f) - 50.0f;
103-
b = stdlib_base_is_positive_zerof( x );
106+
b = stdlib_base_is_positive_zerof( x[ i%100 ] );
104107
if ( b != true && b != false ) {
105108
printf( "should return either true or false\n" );
106109
break;

lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ tape( 'main export is a function', function test( t ) {
3333
});
3434

3535
tape( 'the function returns `true` if provided `+0`', function test( t ) {
36-
t.equal( isPositiveZerof( 0.0 ), true, 'returns true' );
37-
t.equal( isPositiveZerof( +0.0 ), true, 'returns true' );
36+
t.equal( isPositiveZerof( 0.0 ), true, 'returns expected value' );
37+
t.equal( isPositiveZerof( +0.0 ), true, 'returns expected value' );
3838
t.end();
3939
});
4040

4141
tape( 'the function returns `false` if provided `-0`', function test( t ) {
42-
t.equal( isPositiveZerof( -0.0 ), false, 'returns false' );
42+
t.equal( isPositiveZerof( -0.0 ), false, 'returns expected value' );
4343
t.end();
4444
});
4545

@@ -62,7 +62,7 @@ tape( 'the function returns `false` if not provided `+0`', function test( t ) {
6262
];
6363

6464
for ( i = 0; i < values.length; i++ ) {
65-
t.equal( isPositiveZerof( values[i] ), false, 'returns false when provided ' + values[ i ] );
65+
t.equal( isPositiveZerof( values[i] ), false, 'returns expected value when provided ' + values[ i ] );
6666
}
6767
t.end();
6868
});

lib/node_modules/@stdlib/math/base/assert/is-positive-zerof/test/test.native.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ tape( 'main export is a function', opts, function test( t ) {
4242
});
4343

4444
tape( 'the function returns `true` if provided `+0`', opts, function test( t ) {
45-
t.equal( isPositiveZerof( 0.0 ), true, 'returns true' );
46-
t.equal( isPositiveZerof( +0.0 ), true, 'returns true' );
45+
t.equal( isPositiveZerof( 0.0 ), true, 'returns expected value' );
46+
t.equal( isPositiveZerof( +0.0 ), true, 'returns expected value' );
4747
t.end();
4848
});
4949

5050
tape( 'the function returns `false` if provided `-0`', opts, function test( t ) {
51-
t.equal( isPositiveZerof( -0.0 ), false, 'returns false' );
51+
t.equal( isPositiveZerof( -0.0 ), false, 'returns expected value' );
5252
t.end();
5353
});
5454

@@ -71,7 +71,7 @@ tape( 'the function returns `false` if not provided `+0`', opts, function test(
7171
];
7272

7373
for ( i = 0; i < values.length; i++ ) {
74-
t.equal( isPositiveZerof( values[i] ), false, 'returns false when provided ' + values[ i ] );
74+
t.equal( isPositiveZerof( values[i] ), false, 'returns expected value when provided ' + values[ i ] );
7575
}
7676
t.end();
7777
});

lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ var isProbability = require( './../lib' );
3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33-
var len;
33+
var opts;
3434
var x;
3535
var y;
3636
var i;
3737

38-
len = 100;
39-
x = uniform( len, 1.0, -1.0 );
38+
opts = {
39+
'dtype': 'float64'
40+
};
41+
x = uniform( 100, -1.0, 1.0, opts );
4042

4143
b.tic();
4244
for ( i = 0; i < b.iterations; i++ ) {
43-
y = isProbability( x[ i % len ] );
45+
y = isProbability( x[ i % x.length ] );
4446
if ( typeof y !== 'boolean' ) {
4547
b.fail( 'should return a boolean' );
4648
}

lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42-
var len;
42+
var opts;
4343
var x;
4444
var y;
4545
var i;
4646

47-
len = 100;
48-
x = uniform( len, -1.0, 1.0 );
47+
opts = {
48+
'dtype': 'float64'
49+
};
50+
x = uniform( 100, -1.0, 1.0, opts );
4951

5052
b.tic();
5153
for ( i = 0; i < b.iterations; i++ ) {
52-
y = isProbability( x[ i % len ] );
54+
y = isProbability( x[ i % x.length ] );
5355
if ( typeof y !== 'boolean' ) {
5456
b.fail( 'should return a boolean' );
5557
}

lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,18 @@ var isProbabilityf = require( './../lib' );
3131

3232
bench( pkg, function benchmark( b ) {
3333
var opts;
34-
var len;
3534
var x;
3635
var y;
3736
var i;
3837

39-
len = 100;
4038
opts = {
4139
'dtype': 'float32'
4240
};
43-
x = uniform( len, -1.0, 1.0, opts );
41+
x = uniform( 100, -1.0, 1.0, opts );
4442

4543
b.tic();
4644
for ( i = 0; i < b.iterations; i++ ) {
47-
y = isProbabilityf( x[ i % len ] );
45+
y = isProbabilityf( x[ i % x.length ] );
4846
if ( typeof y !== 'boolean' ) {
4947
b.fail( 'should return a boolean' );
5048
}

lib/node_modules/@stdlib/math/base/assert/is-probabilityf/benchmark/benchmark.native.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,18 @@ var opts = {
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
4242
var opts;
43-
var len;
4443
var x;
4544
var y;
4645
var i;
4746

48-
len = 100;
4947
opts = {
5048
'dtype': 'float32'
5149
};
52-
x = uniform( len, -1.0, 1.0, opts );
50+
x = uniform( 100, -1.0, 1.0, opts );
5351

5452
b.tic();
5553
for ( i = 0; i < b.iterations; i++ ) {
56-
y = isProbabilityf( x[ i % len ] );
54+
y = isProbabilityf( x[ i % x.length ] );
5755
if ( typeof y !== 'boolean' ) {
5856
b.fail( 'should return a boolean' );
5957
}

0 commit comments

Comments
 (0)