Skip to content

Commit 890943d

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 1a73ee8 commit 890943d

File tree

3 files changed

+14
-42
lines changed

3 files changed

+14
-42
lines changed

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

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

3232
bench( pkg, function benchmark( b ) {
33-
var len;
3433
var x;
3534
var y;
3635
var i;
3736

38-
len = 100;
39-
x = uniform( len, -50.0, 50.0, {
37+
x = uniform( 100, -50.0, 50.0, {
4038
'dtype': 'float32'
4139
});
4240

4341
b.tic();
4442
for ( i = 0; i < b.iterations; i++ ) {
45-
y = expf( x[ i % len ] );
46-
if ( isnanf( y ) ) {
47-
b.fail( 'should not return NaN' );
48-
}
49-
}
50-
b.toc();
51-
if ( isnanf( y ) ) {
52-
b.fail( 'should not return NaN' );
53-
}
54-
b.pass( 'benchmark finished' );
55-
b.end();
56-
});
57-
58-
bench( pkg+'::built-in', function benchmark( b ) {
59-
var len;
60-
var x;
61-
var y;
62-
var i;
63-
64-
len = 100;
65-
x = uniform( len, -50.0, 50.0, {
66-
'dtype': 'float32'
67-
});
68-
69-
b.tic();
70-
for ( i = 0; i < b.iterations; i++ ) {
71-
y = Math.exp( x[ i % len ] ); // eslint-disable-line stdlib/no-builtin-math
43+
y = expf( x[ i%x.length ] );
7244
if ( isnanf( y ) ) {
7345
b.fail( 'should not return NaN' );
7446
}

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

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

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

47-
len = 100;
48-
x = uniform( len, -50.0, 50.0, {
46+
x = uniform( 100, -50.0, 50.0, {
4947
'dtype': 'float32'
5048
});
5149

5250
b.tic();
5351
for ( i = 0; i < b.iterations; i++ ) {
54-
y = expf( x[ i % len ] );
52+
y = expf( x[ i%x.length ] );
5553
if ( isnanf( y ) ) {
5654
b.fail( 'should not return NaN' );
5755
}

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

Lines changed: 10 additions & 8 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 float rand_float( void ) {
83-
int r = rand();
84-
return (float)r / ( (float)RAND_MAX + 1.0f );
84+
static float random_uniform( const float min, const float max ) {
85+
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
86+
return min + ( v*(max-min) );
8587
}
8688

8789
/**
@@ -90,19 +92,19 @@ static float rand_float( void ) {
9092
* @return elapsed time in seconds
9193
*/
9294
static double benchmark( void ) {
93-
double elapsed;
9495
float x[ 100 ];
96+
double elapsed;
9597
double t;
9698
float y;
9799
int i;
98100

99101
for ( i = 0; i < 100; i++ ) {
100-
x[ i ] = ( 100.0f * rand_float() ) - 50.0f;
102+
x[ i ] = random_uniform( -50.0f, 50.0f );
101103
}
102104

103105
t = tic();
104106
for ( i = 0; i < ITERATIONS; i++ ) {
105-
y = stdlib_base_expf( x[ i % 100 ] );
107+
y = stdlib_base_expf( x[ i%100 ] );
106108
if ( y != y ) {
107109
printf( "should not return NaN\n" );
108110
break;

0 commit comments

Comments
 (0)