Skip to content

Commit 8a1101e

Browse files
committed
bench: add 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent d719d74 commit 8a1101e

2 files changed

Lines changed: 257 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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 Complex128Array = require( '@stdlib/array/complex128' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var format = require( '@stdlib/string/format' );
31+
var pkg = require( './../package.json' ).name;
32+
var zgbmv = require( './../lib/zgbmv.js' );
33+
34+
35+
// VARIABLES //
36+
37+
var options = {
38+
'dtype': 'float64'
39+
};
40+
41+
42+
// FUNCTIONS //
43+
44+
/**
45+
* Creates a benchmark function.
46+
*
47+
* @private
48+
* @param {PositiveInteger} N - array dimension size
49+
* @returns {Function} benchmark function
50+
*/
51+
function createBenchmark( N ) {
52+
var Acompact;
53+
var alpha;
54+
var beta;
55+
var xbuf;
56+
var ybuf;
57+
var Abuf;
58+
var kl;
59+
var ku;
60+
var x;
61+
var y;
62+
63+
xbuf = uniform( N*2, -100.0, 100.0, options );
64+
x = new Complex128Array( xbuf.buffer );
65+
ybuf = uniform( N*2, -100.0, 100.0, options );
66+
y = new Complex128Array( ybuf.buffer );
67+
68+
kl = (N-1)/2;
69+
ku = (N-1)/2;
70+
Abuf = uniform( (kl+ku+1)*N*2, -100.0, 100.0, options );
71+
Acompact = new Complex128Array( Abuf.buffer );
72+
73+
alpha = new Complex128( 0.5, 0.5 );
74+
beta = new Complex128( 0.5, -0.5 );
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 i;
86+
var z;
87+
88+
b.tic();
89+
for ( i = 0; i < b.iterations; i++ ) {
90+
z = zgbmv( 'row-major', 'no-transpose', N, N, kl, ku, alpha, Acompact, (kl+ku+1), x, 1, beta, y, 1 );
91+
if ( isnanf( z[ i%z.length ] ) ) {
92+
b.fail( 'should not return NaN' );
93+
}
94+
}
95+
b.toc();
96+
if ( isnanf( z[ i%z.length ] ) ) {
97+
b.fail( 'should not return NaN' );
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 min;
114+
var max;
115+
var N;
116+
var f;
117+
var i;
118+
119+
min = 1; // 10^min
120+
max = 6; // 10^max
121+
122+
for ( i = min; i <= max; i++ ) {
123+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
124+
f = createBenchmark( N );
125+
bench( format( '%s:size=%d', pkg, N*N ), f );
126+
}
127+
}
128+
129+
main();
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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 Complex128Array = require( '@stdlib/array/complex128' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var format = require( '@stdlib/string/format' );
31+
var pkg = require( './../package.json' ).name;
32+
var zgbmv = require( './../lib/ndarray.js' );
33+
34+
35+
// VARIABLES //
36+
37+
var options = {
38+
'dtype': 'float64'
39+
};
40+
41+
42+
// FUNCTIONS //
43+
44+
/**
45+
* Creates a benchmark function.
46+
*
47+
* @private
48+
* @param {PositiveInteger} N - array dimension size
49+
* @returns {Function} benchmark function
50+
*/
51+
function createBenchmark( N ) {
52+
var Acompact;
53+
var alpha;
54+
var beta;
55+
var xbuf;
56+
var ybuf;
57+
var Abuf;
58+
var kl;
59+
var ku;
60+
var x;
61+
var y;
62+
63+
xbuf = uniform( N*2, -100.0, 100.0, options );
64+
x = new Complex128Array( xbuf.buffer );
65+
ybuf = uniform( N*2, -100.0, 100.0, options );
66+
y = new Complex128Array( ybuf.buffer );
67+
kl = (N-1)/2;
68+
ku = (N-1)/2;
69+
Abuf = uniform( (kl+ku+1)*N*2, -100.0, 100.0, options );
70+
Acompact = new Complex128Array( Abuf.buffer );
71+
72+
alpha = new Complex128( 0.5, 0.5 );
73+
beta = new Complex128( 0.5, -0.5 );
74+
75+
return benchmark;
76+
77+
/**
78+
* Benchmark function.
79+
*
80+
* @private
81+
* @param {Benchmark} b - benchmark instance
82+
*/
83+
function benchmark( b ) {
84+
var i;
85+
var z;
86+
87+
b.tic();
88+
for ( i = 0; i < b.iterations; i++ ) {
89+
z = zgbmv( 'no-transpose', N, N, kl, ku, alpha, Acompact, 1, (kl+ku+1), 0, x, 1, 0, beta, y, 1, 0 );
90+
if ( isnanf( z[ i%z.length ] ) ) {
91+
b.fail( 'should not return NaN' );
92+
}
93+
}
94+
b.toc();
95+
if ( isnanf( z[ i%z.length ] ) ) {
96+
b.fail( 'should not return NaN' );
97+
}
98+
b.pass( 'benchmark finished' );
99+
b.end();
100+
}
101+
}
102+
103+
104+
// MAIN //
105+
106+
/**
107+
* Main execution sequence.
108+
*
109+
* @private
110+
*/
111+
function main() {
112+
var min;
113+
var max;
114+
var N;
115+
var f;
116+
var i;
117+
118+
min = 1; // 10^min
119+
max = 6; // 10^max
120+
121+
for ( i = min; i <= max; i++ ) {
122+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
123+
f = createBenchmark( N );
124+
bench( format( '%s:ndarray:size=%d', pkg, N*N ), f );
125+
}
126+
}
127+
128+
main();

0 commit comments

Comments
 (0)