Skip to content

Commit 671c703

Browse files
committed
bench: add benchmark
--- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 84c1054 commit 671c703

2 files changed

Lines changed: 233 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var Complex64Array = require( '@stdlib/array/complex64' );
29+
var format = require( '@stdlib/string/format' );
30+
var pkg = require( './../package.json' ).name;
31+
var ctbmv = require( './../lib/ctbmv.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'float32'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} N - array dimension size
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( N ) {
51+
var xbuf;
52+
var Abuf;
53+
var A;
54+
var K;
55+
var x;
56+
57+
xbuf = uniform( N*2, -100.0, 100.0, options );
58+
x = new Complex64Array( xbuf.buffer );
59+
60+
K = N - 1;
61+
Abuf = uniform( (K+1)*N*2, -100.0, 100.0, options );
62+
A = new Complex64Array( Abuf.buffer );
63+
64+
return benchmark;
65+
66+
/**
67+
* Benchmark function.
68+
*
69+
* @private
70+
* @param {Benchmark} b - benchmark instance
71+
*/
72+
function benchmark( b ) {
73+
var i;
74+
var z;
75+
76+
b.tic();
77+
for ( i = 0; i < b.iterations; i++ ) {
78+
z = ctbmv( 'row-major', 'upper', 'transpose', 'non-unit', N, 1, A, (K+1), x, 1 );
79+
if ( isnanf( z[ i % ( z.length ) ] ) ) {
80+
b.fail( 'should not return NaN' );
81+
}
82+
}
83+
b.toc();
84+
if ( isnanf( z[ i % ( z.length ) ] ) ) {
85+
b.fail( 'should not return NaN' );
86+
}
87+
b.pass( 'benchmark finished' );
88+
b.end();
89+
}
90+
}
91+
92+
93+
// MAIN //
94+
95+
/**
96+
* Main execution sequence.
97+
*
98+
* @private
99+
*/
100+
function main() {
101+
var min;
102+
var max;
103+
var N;
104+
var f;
105+
var i;
106+
107+
min = 1; // 10^min
108+
max = 6; // 10^max
109+
110+
for ( i = min; i <= max; i++ ) {
111+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
112+
f = createBenchmark( N );
113+
bench( format( '%s:size=%d', pkg, N*N ), f );
114+
}
115+
}
116+
117+
main();
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var Complex64Array = require( '@stdlib/array/complex64' );
29+
var format = require( '@stdlib/string/format' );
30+
var pkg = require( './../package.json' ).name;
31+
var ctbmv = require( './../lib/ndarray.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'float32'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} N - array dimension size
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( N ) {
51+
var xbuf;
52+
var Abuf;
53+
var A;
54+
var K;
55+
var x;
56+
57+
xbuf = uniform( N*2, -100.0, 100.0, options );
58+
x = new Complex64Array( xbuf.buffer );
59+
K = N - 1;
60+
Abuf = uniform( (K+1)*N*2, -100.0, 100.0, options );
61+
A = new Complex64Array( Abuf.buffer );
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 i;
73+
var z;
74+
75+
b.tic();
76+
for ( i = 0; i < b.iterations; i++ ) {
77+
z = ctbmv( 'upper', 'transpose', 'non-unit', N, 1, A, (K+1), 1, 0, x, 1, 0 );
78+
if ( isnanf( z[ i%(z.length) ] ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
}
82+
b.toc();
83+
if ( isnanf( z[ i%(z.length) ] ) ) {
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 min;
101+
var max;
102+
var N;
103+
var f;
104+
var i;
105+
106+
min = 1; // 10^min
107+
max = 6; // 10^max
108+
109+
for ( i = min; i <= max; i++ ) {
110+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
111+
f = createBenchmark( N );
112+
bench( format( '%s:ndarray:size=%d', pkg, N*N ), f );
113+
}
114+
}
115+
116+
main();

0 commit comments

Comments
 (0)