Skip to content

Commit 5c64409

Browse files
bench: refactor base/special/cbrt*
--- 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: passed - 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 7141f46 commit 5c64409

File tree

15 files changed

+99
-47
lines changed

15 files changed

+99
-47
lines changed

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

Lines changed: 16 additions & 7 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/base/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2627
var pkg = require( './../package.json' ).name;
2728
var cbrt = require( './../lib' );
2829

@@ -37,14 +38,18 @@ var opts = {
3738
// MAIN //
3839

3940
bench( pkg, function benchmark( b ) {
40-
var x;
41+
var values;
4142
var y;
4243
var i;
4344

45+
values = [
46+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
47+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
48+
];
49+
4450
b.tic();
4551
for ( i = 0; i < b.iterations; i++ ) {
46-
x = ( randu()*1000.0 ) - 500.0;
47-
y = cbrt( x );
52+
y = cbrt( values[ i%values.length ] );
4853
if ( isnan( y ) ) {
4954
b.fail( 'should not return NaN' );
5055
}
@@ -58,14 +63,18 @@ bench( pkg, function benchmark( b ) {
5863
});
5964

6065
bench( pkg+'::built-in', opts, function benchmark( b ) {
61-
var x;
66+
var values;
6267
var y;
6368
var i;
6469

70+
values = [
71+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
72+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
73+
];
74+
6575
b.tic();
6676
for ( i = 0; i < b.iterations; i++ ) {
67-
x = ( randu()*1000.0 ) - 500.0;
68-
y = Math.cbrt( x ); // eslint-disable-line stdlib/no-builtin-math
77+
y = Math.cbrt( values[ i%values.length ]); // eslint-disable-line stdlib/no-builtin-math
6978
if ( isnan( y ) ) {
7079
b.fail( 'should not return NaN' );
7180
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
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/base/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829
var pkg = require( './../package.json' ).name;
2930

@@ -39,14 +40,18 @@ var opts = {
3940
// MAIN //
4041

4142
bench( pkg+'::native', opts, function benchmark( b ) {
42-
var x;
43+
var values;
4344
var y;
4445
var i;
4546

47+
values = [
48+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
49+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
50+
];
51+
4652
b.tic();
4753
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( 1000.0*randu() ) - 500.0;
49-
y = cbrt( x );
54+
y = cbrt( values[ i%values.length ] );
5055
if ( isnan( y ) ) {
5156
b.fail( 'should not return NaN' );
5257
}

lib/node_modules/@stdlib/math/base/special/cbrt/benchmark/c/benchmark.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "stdlib/math/base/special/cbrt.h"
1920
#include <stdlib.h>
2021
#include <stdio.h>
2122
#include <math.h>
@@ -89,16 +90,19 @@ static double rand_double( void ) {
8990
* @return elapsed time in seconds
9091
*/
9192
static double benchmark( void ) {
93+
double x[ 100 ];
9294
double elapsed;
93-
double x;
9495
double y;
9596
double t;
9697
int i;
9798

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
101+
}
102+
98103
t = tic();
99104
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 1000.0*rand_double() ) - 500.0;
101-
y = cbrt( x );
105+
y = stdlib_base_cbrt( x[ i%100 ] );
102106
if ( y != y ) {
103107
printf( "should not return NaN\n" );
104108
break;

lib/node_modules/@stdlib/math/base/special/cbrt/benchmark/c/cephes/benchmark.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "stdlib/math/base/special/cbrt.h"
1920
#include <stdlib.h>
2021
#include <stdio.h>
2122
#include <math.h>
@@ -94,16 +95,19 @@ static double rand_double( void ) {
9495
* @return elapsed time in seconds
9596
*/
9697
static double benchmark( void ) {
98+
double x[ 100 ];
9799
double elapsed;
98-
double x;
99100
double y;
100101
double t;
101102
int i;
102103

104+
for ( i = 0; i < 100; i++ ) {
105+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
106+
}
107+
103108
t = tic();
104109
for ( i = 0; i < ITERATIONS; i++ ) {
105-
x = ( 1000.0*rand_double() ) - 500.0;
106-
y = cbrt( x );
110+
y = stdlib_base_cbrt( x[ i%100 ] );
107111
if ( y != y ) {
108112
printf( "should not return NaN\n" );
109113
break;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
double x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double y;
9696
double t;
9797
int i;
9898

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

lib/node_modules/@stdlib/math/base/special/cbrt/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', function t
383383

384384
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
385385
var v = cbrt( NaN );
386-
t.equal( isnan( v ), true, 'returns NaN' );
386+
t.equal( isnan( v ), true, 'returns expected value' );
387387
t.end();
388388
});
389389

lib/node_modules/@stdlib/math/base/special/cbrt/test/test.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', opts, func
392392

393393
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
394394
var v = cbrt( NaN );
395-
t.equal( isnan( v ), true, 'returns NaN' );
395+
t.equal( isnan( v ), true, 'returns expected value' );
396396
t.end();
397397
});
398398

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

Lines changed: 16 additions & 7 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/base/uniform' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2627
var pkg = require( './../package.json' ).name;
2728
var cbrtf = require( './../lib' );
2829

@@ -37,14 +38,18 @@ var opts = {
3738
// MAIN //
3839

3940
bench( pkg, function benchmark( b ) {
40-
var x;
41+
var values;
4142
var y;
4243
var i;
4344

45+
values = [
46+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
47+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
48+
];
49+
4450
b.tic();
4551
for ( i = 0; i < b.iterations; i++ ) {
46-
x = ( randu()*1000.0 ) - 500.0;
47-
y = cbrtf( x );
52+
y = cbrtf( values[ i%values.length ] );
4853
if ( isnanf( y ) ) {
4954
b.fail( 'should not return NaN' );
5055
}
@@ -58,14 +63,18 @@ bench( pkg, function benchmark( b ) {
5863
});
5964

6065
bench( pkg+'::built-in', opts, function benchmark( b ) {
61-
var x;
66+
var values;
6267
var y;
6368
var i;
6469

70+
values = [
71+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
72+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
73+
];
74+
6575
b.tic();
6676
for ( i = 0; i < b.iterations; i++ ) {
67-
x = ( randu()*1000.0 ) - 500.0;
68-
y = Math.cbrt( x ); // eslint-disable-line stdlib/no-builtin-math
77+
y = Math.cbrt( values[ i%values.length ] ); // eslint-disable-line stdlib/no-builtin-math
6978
if ( isnanf( y ) ) {
7079
b.fail( 'should not return NaN' );
7180
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
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/base/uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829
var pkg = require( './../package.json' ).name;
2930

@@ -39,14 +40,18 @@ var opts = {
3940
// MAIN //
4041

4142
bench( pkg+'::native', opts, function benchmark( b ) {
42-
var x;
43+
var values;
4344
var y;
4445
var i;
4546

47+
values = [
48+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
49+
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
50+
];
51+
4652
b.tic();
4753
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( 1000.0*randu() ) - 500.0;
49-
y = cbrtf( x );
54+
y = cbrtf( values[ i%values.length ] );
5055
if ( isnanf( y ) ) {
5156
b.fail( 'should not return NaN' );
5257
}

lib/node_modules/@stdlib/math/base/special/cbrtf/benchmark/c/benchmark.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "stdlib/math/base/special/cbrtf.h"
1920
#include <stdlib.h>
2021
#include <stdio.h>
2122
#include <math.h>
@@ -89,16 +90,19 @@ static float rand_float( void ) {
8990
* @return elapsed time in seconds
9091
*/
9192
static double benchmark( void ) {
93+
float x[ 100 ];
9294
double elapsed;
93-
float x;
9495
float y;
9596
double t;
9697
int i;
9798

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
101+
}
102+
98103
t = tic();
99104
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 1000.0f*rand_float() ) - 500.0f;
101-
y = cbrtf( x );
105+
y = stdlib_base_cbrtf( x[ i%100 ] );
102106
if ( y != y ) {
103107
printf( "should not return NaN\n" );
104108
break;

0 commit comments

Comments
 (0)