Skip to content

Commit 63895af

Browse files
committed
bench: update random value generation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 9bfc43a commit 63895af

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

lib/node_modules/@stdlib/math/base/special/kernel-log1p/benchmark/benchmark.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var FLOAT64_SQRT_HALF = require( '@stdlib/constants/float64/sqrt-half' );
27+
var FLOAT64_SQRT_TWO = require( '@stdlib/constants/float64/sqrt-two' );
2628
var pkg = require( './../package.json' ).name;
2729
var kernelLog1p = require( './../lib' );
2830

@@ -34,10 +36,11 @@ bench( pkg, function benchmark( b ) {
3436
var y;
3537
var i;
3638

39+
x = uniform( 100, FLOAT64_SQRT_HALF, FLOAT64_SQRT_TWO );
40+
3741
b.tic();
3842
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu() + 1.0 ) * 0.7071067811865476;
40-
y = kernelLog1p( x );
43+
y = kernelLog1p( x[ i%x.length ] );
4144
if ( isnan( y ) ) {
4245
b.fail( 'should not return NaN' );
4346
}

lib/node_modules/@stdlib/math/base/special/kernel-log1p/benchmark/benchmark.native.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var FLOAT64_SQRT_HALF = require( '@stdlib/constants/float64/sqrt-half' );
29+
var FLOAT64_SQRT_TWO = require( '@stdlib/constants/float64/sqrt-two' );
2830
var pkg = require( './../package.json' ).name;
2931

3032

@@ -43,10 +45,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4345
var y;
4446
var i;
4547

48+
x = uniform( 100, FLOAT64_SQRT_HALF, FLOAT64_SQRT_TWO );
49+
4650
b.tic();
4751
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu() + 1.0 ) * 0.7071067811865476;
49-
y = kernelLog1p( x );
52+
y = kernelLog1p( x[ i%x.length ] );
5053
if ( isnan( y ) ) {
5154
b.fail( 'should not return NaN' );
5255
}

lib/node_modules/@stdlib/math/base/special/kernel-log1p/benchmark/c/native/benchmark.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ static double tic( void ) {
7575
}
7676

7777
/**
78-
* Generates a random number on the interval [0,1).
78+
* Generates a random number on the interval [min,max).
7979
*
80-
* @return random number
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
8183
*/
82-
static double rand_double( void ) {
83-
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
static double random_uniform( const double min, const double max ) {
85+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
86+
return min + ( v*(max-min) );
8587
}
8688

8789
/**
@@ -91,15 +93,18 @@ static double rand_double( void ) {
9193
*/
9294
static double benchmark( void ) {
9395
double elapsed;
94-
double x;
96+
double x[100];
9597
double z;
9698
double t;
9799
int i;
98100

101+
for ( i = 0; i < 100; i++ ) {
102+
x[ i ] = random_uniform( 0.7071067811865476, 1.4142135623730951 ); // ~[sqrt(2)/2, sqrt(2)]
103+
}
104+
99105
t = tic();
100106
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( rand_double() + 1.0 ) * 0.7071067811865476;
102-
z = stdlib_base_kernel_log1p( x );
107+
z = stdlib_base_kernel_log1p( x[ i%100 ] );
103108
if ( z != z ) {
104109
printf( "should not return NaN\n" );
105110
break;
@@ -124,7 +129,7 @@ int main( void ) {
124129

125130
print_version();
126131
for ( i = 0; i < REPEATS; i++ ) {
127-
printf( "# c::%s\n", NAME );
132+
printf( "# c::native::%s\n", NAME );
128133
elapsed = benchmark();
129134
print_results( elapsed );
130135
printf( "ok %d benchmark finished\n", i+1 );

0 commit comments

Comments
 (0)