Skip to content

Commit 6cd22c0

Browse files
committed
bench: add 9d 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 3d2d0cf commit 6cd22c0

File tree

4 files changed

+588
-0
lines changed

4 files changed

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

0 commit comments

Comments
 (0)