Skip to content

Commit c0126f6

Browse files
committed
bench: add benchmaks
--- 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: passed - 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 1e90999 commit c0126f6

File tree

3 files changed

+306
-0
lines changed

3 files changed

+306
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var pkg = require( './../package.json' ).name;
28+
var dlaqr1 = require( './../lib/dlaqr1.js' );
29+
30+
31+
// VARIABLES //
32+
33+
var LAYOUTS = [
34+
'row-major',
35+
'column-major'
36+
];
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {string} order - storage layout
46+
* @param {PositiveInteger} N - number of elements along each dimension
47+
* @returns {Function} benchmark function
48+
*/
49+
function createBenchmark( order, N ) {
50+
var values;
51+
var H;
52+
var V;
53+
54+
H = uniform( N*N, -10.0, 10.0, {
55+
'dtype': 'float64'
56+
});
57+
values = uniform( N, -10.0, 10.0, {
58+
'dtype': 'float64'
59+
});
60+
V = new Float64Array( N );
61+
return benchmark;
62+
63+
/**
64+
* Benchmark function.
65+
*
66+
* @private
67+
* @param {Benchmark} b - benchmark instance
68+
*/
69+
function benchmark( b ) {
70+
var z;
71+
var i;
72+
73+
b.tic();
74+
for ( i = 0; i < b.iterations; i++ ) {
75+
z = dlaqr1( order, N, H, N, values[ i%N ], values[ (i+1)%N ], values[ (i+2)%N ], values[ (i+3)%N ], V ); // eslint-disable-line max-len
76+
if ( isnan( z[ i%z.length ] ) ) {
77+
b.fail( 'should not return NaN' );
78+
}
79+
}
80+
b.toc();
81+
if ( isnan( z[ i%z.length ] ) ) {
82+
b.fail( 'should not return NaN' );
83+
}
84+
b.pass( 'benchmark finished' );
85+
b.end();
86+
}
87+
}
88+
89+
90+
// MAIN //
91+
92+
/**
93+
* Main execution sequence.
94+
*
95+
* @private
96+
*/
97+
function main() {
98+
var ord;
99+
var N;
100+
var f;
101+
var i;
102+
103+
for ( i = 0; i < LAYOUTS.length; i++ ) {
104+
ord = LAYOUTS[ i ];
105+
for ( N = 2; N <= 3; N++ ) {
106+
f = createBenchmark( ord, N );
107+
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
108+
}
109+
}
110+
}
111+
112+
main();
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var Float64Array = require( '@stdlib/array/float64' );
28+
var pkg = require( './../package.json' ).name;
29+
var dlaqr1 = require( './../lib/ndarray.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var LAYOUTS = [
35+
'row-major',
36+
'column-major'
37+
];
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {string} order - storage layout
47+
* @param {PositiveInteger} N - number of elements along each dimension
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( order, N ) {
51+
var values;
52+
var sh1;
53+
var sh2;
54+
var H;
55+
var V;
56+
57+
if ( isColumnMajor( order ) ) {
58+
sh1 = 1;
59+
sh2 = N;
60+
} else { // order === 'row-major'
61+
sh1 = N;
62+
sh2 = 1;
63+
}
64+
H = uniform( N*N, -10.0, 10.0, {
65+
'dtype': 'float64'
66+
});
67+
values = uniform( N, -10.0, 10.0, {
68+
'dtype': 'float64'
69+
});
70+
V = new Float64Array( N );
71+
return benchmark;
72+
73+
/**
74+
* Benchmark function.
75+
*
76+
* @private
77+
* @param {Benchmark} b - benchmark instance
78+
*/
79+
function benchmark( b ) {
80+
var z;
81+
var i;
82+
83+
b.tic();
84+
for ( i = 0; i < b.iterations; i++ ) {
85+
z = dlaqr1( N, H, sh1, sh2, 0, values[ i%N ], values[ (i+1)%N ], values[ (i+2)%N ], values[ (i+3)%N ], V, 1, 0 ); // eslint-disable-line max-len
86+
if ( isnan( z[ i%z.length ] ) ) {
87+
b.fail( 'should not return NaN' );
88+
}
89+
}
90+
b.toc();
91+
if ( isnan( 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 ord;
109+
var N;
110+
var f;
111+
var i;
112+
113+
for ( i = 0; i < LAYOUTS.length; i++ ) {
114+
ord = LAYOUTS[ i ];
115+
for ( N = 2; N <= 3; N++ ) {
116+
f = createBenchmark( ord, N );
117+
bench( pkg+'::square_matrix:ndarray:order='+ord+',size='+(N*N), f );
118+
}
119+
}
120+
}
121+
122+
main();
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@stdlib/lapack/base/dlaqr1",
3+
"version": "0.0.0",
4+
"description": "Given a 2-by-2 or a 3-by-3 matrix, this LAPACK routine sets `V` to a scalar multiple of the first column of `K` where `K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)`.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"benchmark": "./benchmark",
19+
"doc": "./docs",
20+
"example": "./examples",
21+
"lib": "./lib",
22+
"test": "./test"
23+
},
24+
"types": "./docs/types",
25+
"scripts": {},
26+
"homepage": "https://github.com/stdlib-js/stdlib",
27+
"repository": {
28+
"type": "git",
29+
"url": "git://github.com/stdlib-js/stdlib.git"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/stdlib-js/stdlib/issues"
33+
},
34+
"dependencies": {},
35+
"devDependencies": {},
36+
"engines": {
37+
"node": ">=0.10.0",
38+
"npm": ">2.7.0"
39+
},
40+
"os": [
41+
"aix",
42+
"darwin",
43+
"freebsd",
44+
"linux",
45+
"macos",
46+
"openbsd",
47+
"sunos",
48+
"win32",
49+
"windows"
50+
],
51+
"keywords": [
52+
"stdlib",
53+
"stdmath",
54+
"mathematics",
55+
"math",
56+
"lapack",
57+
"dlaqr1",
58+
"interchange",
59+
"swap",
60+
"exchange",
61+
"permute",
62+
"permutedims",
63+
"linear",
64+
"algebra",
65+
"subroutines",
66+
"array",
67+
"ndarray",
68+
"float64",
69+
"double",
70+
"float64array"
71+
]
72+
}

0 commit comments

Comments
 (0)