Skip to content

Commit 556aab6

Browse files
kgryteNeerajpathak07
authored andcommitted
bench: add 10d benchmarks
--- 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: na - 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 5597a0d commit 556aab6

File tree

4 files changed

+536
-0
lines changed

4 files changed

+536
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 bench = require( '@stdlib/bench' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var floor = require( '@stdlib/math/base/special/floor' );
27+
var uniform = require( '@stdlib/random/array/uniform' );
28+
var add = require( '@stdlib/math/base/ops/add' );
29+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
30+
var pkg = require( './../package.json' ).name;
31+
var accumulateUnary = require( './../lib/10d_blocked.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var types = [ 'float64' ];
37+
var order = 'column-major';
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} len - ndarray length
47+
* @param {NonNegativeIntegerArray} shape - ndarray shape
48+
* @param {string} xtype - input ndarray data type
49+
* @returns {Function} benchmark function
50+
*/
51+
function createBenchmark( len, shape, xtype ) {
52+
var x = uniform( len, -100.0, 100.0, {
53+
'dtype': xtype
54+
});
55+
x = {
56+
'dtype': xtype,
57+
'data': x,
58+
'shape': shape,
59+
'strides': shape2strides( shape, order ),
60+
'offset': 0,
61+
'order': order
62+
};
63+
return benchmark;
64+
65+
/**
66+
* Benchmark function.
67+
*
68+
* @private
69+
* @param {Benchmark} b - benchmark instance
70+
*/
71+
function benchmark( b ) {
72+
var out;
73+
var i;
74+
75+
b.tic();
76+
for ( i = 0; i < b.iterations; i++ ) {
77+
out = accumulateUnary( x, 0.0, add );
78+
if ( isnan( out ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
}
82+
b.toc();
83+
if ( isnan( out ) ) {
84+
b.fail( 'should not return NaN' );
85+
}
86+
b.pass( 'benchmark finished' );
87+
b.end();
88+
}
89+
}
90+
91+
92+
// MAIN //
93+
94+
/**
95+
* Main execution sequence.
96+
*
97+
* @private
98+
*/
99+
function main() {
100+
var len;
101+
var min;
102+
var max;
103+
var sh;
104+
var t1;
105+
var f;
106+
var i;
107+
var j;
108+
109+
min = 1; // 10^min
110+
max = 6; // 10^max
111+
112+
for ( j = 0; j < types.length; j++ ) {
113+
t1 = types[ j ];
114+
for ( i = min; i <= max; i++ ) {
115+
len = pow( 10, i );
116+
117+
sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ];
118+
f = createBenchmark( len, sh, t1 );
119+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
120+
121+
sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ];
122+
f = createBenchmark( len, sh, t1 );
123+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
124+
125+
len = floor( pow( len, 1.0/10.0 ) );
126+
sh = [ len, len, len, len, len, len, len, len, len, len ];
127+
len *= pow( len, 9 );
128+
f = createBenchmark( len, sh, t1 );
129+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
130+
}
131+
}
132+
}
133+
134+
main();
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 bench = require( '@stdlib/bench' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var floor = require( '@stdlib/math/base/special/floor' );
27+
var uniform = require( '@stdlib/random/array/uniform' );
28+
var add = require( '@stdlib/math/base/ops/add' );
29+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
30+
var pkg = require( './../package.json' ).name;
31+
var accumulateUnary = require( './../lib/10d_blocked.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var types = [ 'float64' ];
37+
var order = 'row-major';
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} len - ndarray length
47+
* @param {NonNegativeIntegerArray} shape - ndarray shape
48+
* @param {string} xtype - input ndarray data type
49+
* @returns {Function} benchmark function
50+
*/
51+
function createBenchmark( len, shape, xtype ) {
52+
var x = uniform( len, -100.0, 100.0, {
53+
'dtype': xtype
54+
});
55+
x = {
56+
'dtype': xtype,
57+
'data': x,
58+
'shape': shape,
59+
'strides': shape2strides( shape, order ),
60+
'offset': 0,
61+
'order': order
62+
};
63+
return benchmark;
64+
65+
/**
66+
* Benchmark function.
67+
*
68+
* @private
69+
* @param {Benchmark} b - benchmark instance
70+
*/
71+
function benchmark( b ) {
72+
var out;
73+
var i;
74+
75+
b.tic();
76+
for ( i = 0; i < b.iterations; i++ ) {
77+
out = accumulateUnary( x, 0.0, add );
78+
if ( isnan( out ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
}
82+
b.toc();
83+
if ( isnan( out ) ) {
84+
b.fail( 'should not return NaN' );
85+
}
86+
b.pass( 'benchmark finished' );
87+
b.end();
88+
}
89+
}
90+
91+
92+
// MAIN //
93+
94+
/**
95+
* Main execution sequence.
96+
*
97+
* @private
98+
*/
99+
function main() {
100+
var len;
101+
var min;
102+
var max;
103+
var sh;
104+
var t1;
105+
var f;
106+
var i;
107+
var j;
108+
109+
min = 1; // 10^min
110+
max = 6; // 10^max
111+
112+
for ( j = 0; j < types.length; j++ ) {
113+
t1 = types[ j ];
114+
for ( i = min; i <= max; i++ ) {
115+
len = pow( 10, i );
116+
117+
sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ];
118+
f = createBenchmark( len, sh, t1 );
119+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
120+
121+
sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ];
122+
f = createBenchmark( len, sh, t1 );
123+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
124+
125+
len = floor( pow( len, 1.0/10.0 ) );
126+
sh = [ len, len, len, len, len, len, len, len, len, len ];
127+
len *= pow( len, 9 );
128+
f = createBenchmark( len, sh, t1 );
129+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
130+
}
131+
}
132+
}
133+
134+
main();

0 commit comments

Comments
 (0)