Skip to content

Commit e02964d

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 659340f commit e02964d

2 files changed

Lines changed: 248 additions & 0 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 zhemv = require( './../lib/zhemv.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 alpha;
53+
var beta;
54+
var xbuf;
55+
var ybuf;
56+
var Abuf;
57+
var x;
58+
var y;
59+
var A;
60+
61+
xbuf = uniform( N*2, -100.0, 100.0, options );
62+
x = new Complex128Array( xbuf.buffer );
63+
ybuf = uniform( N*2, -100.0, 100.0, options );
64+
y = new Complex128Array( ybuf.buffer );
65+
Abuf = uniform( (N*N)*2, -100.0, 100.0, options );
66+
A = new Complex128Array( Abuf.buffer );
67+
68+
alpha = new Complex128( 0.5, 0.5 );
69+
beta = new Complex128( 0.5, -0.5 );
70+
71+
return benchmark;
72+
73+
/**
74+
* Benchmark function.
75+
*
76+
* @private
77+
* @param {Benchmark} b - benchmark instance
78+
*/
79+
function benchmark( b ) {
80+
var i;
81+
var z;
82+
83+
b.tic();
84+
for ( i = 0; i < b.iterations; i++ ) {
85+
z = zhemv( 'row-major', 'lower', N, alpha, A, N, x, 1, beta, y, 1 );
86+
if ( isnanf( z[ i%z.length ] ) ) {
87+
b.fail( 'should not return NaN' );
88+
}
89+
}
90+
b.toc();
91+
if ( isnanf( z[ i%z.length ] ) ) {
92+
b.fail( 'should not return NaN' );
93+
}
94+
b.pass( 'benchmark finished' );
95+
b.end();
96+
}
97+
}
98+
99+
100+
// MAIN //
101+
102+
/**
103+
* Main execution sequence.
104+
*
105+
* @private
106+
*/
107+
function main() {
108+
var min;
109+
var max;
110+
var N;
111+
var f;
112+
var i;
113+
114+
min = 1; // 10^min
115+
max = 6; // 10^max
116+
117+
for ( i = min; i <= max; i++ ) {
118+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
119+
f = createBenchmark( N );
120+
bench( format( '%s:size=%d', pkg, N*N ), f );
121+
}
122+
}
123+
124+
main();
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 zhemv = 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 alpha;
53+
var beta;
54+
var xbuf;
55+
var ybuf;
56+
var Abuf;
57+
var x;
58+
var y;
59+
var A;
60+
61+
xbuf = uniform( N*2, -100.0, 100.0, options );
62+
x = new Complex128Array( xbuf.buffer );
63+
ybuf = uniform( N*2, -100.0, 100.0, options );
64+
y = new Complex128Array( ybuf.buffer );
65+
Abuf = uniform( (N*N)*2, -100.0, 100.0, options );
66+
A = new Complex128Array( Abuf.buffer );
67+
68+
alpha = new Complex128( 0.5, 0.5 );
69+
beta = new Complex128( 0.5, -0.5 );
70+
71+
return benchmark;
72+
73+
/**
74+
* Benchmark function.
75+
*
76+
* @private
77+
* @param {Benchmark} b - benchmark instance
78+
*/
79+
function benchmark( b ) {
80+
var i;
81+
var z;
82+
83+
b.tic();
84+
for ( i = 0; i < b.iterations; i++ ) {
85+
z = zhemv( 'lower', N, alpha, A, 1, N, 0, x, 1, 0, beta, y, 1, 0 );
86+
if ( isnanf( z[ i%z.length ] ) ) {
87+
b.fail( 'should not return NaN' );
88+
}
89+
}
90+
b.toc();
91+
if ( isnanf( z[ i%z.length ] ) ) {
92+
b.fail( 'should not return NaN' );
93+
}
94+
b.pass( 'benchmark finished' );
95+
b.end();
96+
}
97+
}
98+
99+
100+
// MAIN //
101+
102+
/**
103+
* Main execution sequence.
104+
*
105+
* @private
106+
*/
107+
function main() {
108+
var min;
109+
var max;
110+
var N;
111+
var f;
112+
var i;
113+
114+
min = 1; // 10^min
115+
max = 6; // 10^max
116+
117+
for ( i = min; i <= max; i++ ) {
118+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
119+
f = createBenchmark( N );
120+
bench( format( '%s:ndarray:size=%d', pkg, N*N ), f );
121+
}
122+
}
123+
124+
main();

0 commit comments

Comments
 (0)