Skip to content

Commit 75954bb

Browse files
committed
Added the Javascript benchmark files
1 parent 2812057 commit 75954bb

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var Float64Array = require( '@stdlib/array/float64' );
26+
var randu = require( '@stdlib/random/base/randu' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var skewness = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( skewness instanceof Error )
37+
};
38+
39+
40+
// MAIN //
41+
42+
bench( pkg+'::native', opts, function benchmark( b ) {
43+
var len;
44+
var min;
45+
var max;
46+
var y;
47+
var i;
48+
49+
len = 100;
50+
min = new Float64Array( len );
51+
max = new Float64Array( len );
52+
for ( i = 0; i < len; i++ ) {
53+
min[ i ] = ( randu() * 20.0 ) - 20.0;
54+
max[ i ] = min[ i ] + ( randu() * 40.0 );
55+
}
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
y = skewness( min[ i % len ], max[ i % len ] );
60+
if ( isnan( y ) ) {
61+
b.fail( 'should not return NaN' );
62+
}
63+
}
64+
b.toc();
65+
if ( isnan( y ) ) {
66+
b.fail( 'should not return NaN' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var addon = require( './../src/addon.node' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Returns the skewness of an arcsine distribution with minimum support `a` and maximum support `b`.
30+
*
31+
* @private
32+
* @param {number} a - minimum support
33+
* @param {number} b - maximum support
34+
* @returns {number} skewness
35+
*
36+
* @example
37+
* var y = skewness( 0.0, 1.0 );
38+
* // returns 0.0
39+
*
40+
* @example
41+
* var y = skewness( 4.0, 12.0 );
42+
* // returns 0.0
43+
*
44+
* @example
45+
* var y = skewness( -4.0, 4.0 );
46+
* // returns 0.0
47+
*
48+
* @example
49+
* var y = skewness( +Infinity, 4.0 );
50+
* // returns NaN
51+
*
52+
* @example
53+
* var y = skewness( -Infinity, 4.0 );
54+
* // returns NaN
55+
*
56+
* @example
57+
* var y = skewness( 1.0, NaN );
58+
* // returns NaN
59+
*
60+
* @example
61+
* var y = skewness( NaN, 2.0 );
62+
* // returns NaN
63+
*/
64+
function skewness( a, b ) {
65+
return addon( a, b );
66+
}
67+
68+
69+
// EXPORTS //
70+
71+
module.exports = skewness;

0 commit comments

Comments
 (0)