Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions lib/node_modules/@stdlib/blas/base/zgemv/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex128Array = require( '@stdlib/array/complex128' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var pkg = require( './../package.json' ).name;
var zgemv = require( './../lib/zgemv.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - array dimension size
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var alpha;
var beta;
var xbuf;
var ybuf;
var Abuf;
var x;
var y;
var A;

xbuf = uniform( N*2, -100.0, 100.0, options );
x = new Complex128Array( xbuf.buffer );
ybuf = uniform( N*2, -100.0, 100.0, options );
y = new Complex128Array( ybuf.buffer );
Abuf = uniform( (N*N)*2, -100.0, 100.0, options );
A = new Complex128Array( Abuf.buffer );

alpha = new Complex128( 1.0, 0.0 );
beta = new Complex128( 1.0, 0.0 );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
zgemv( 'row-major', 'no-transpose', N, N, alpha, A, N, x, 1, beta, y, 1 );
if ( isnan( ybuf[ i%N ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( ybuf[ i%N ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var min;
var max;
var N;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
N = pow( 10, i );
f = createBenchmark( N );
bench( pkg+':size='+N, f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex128Array = require( '@stdlib/array/complex128' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var pkg = require( './../package.json' ).name;
var zgemv = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - array dimension size
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var alpha;
var beta;
var xbuf;
var ybuf;
var Abuf;
var x;
var y;
var A;

xbuf = uniform( N*2, -100.0, 100.0, options );
x = new Complex128Array( xbuf.buffer );
ybuf = uniform( N*2, -100.0, 100.0, options );
y = new Complex128Array( ybuf.buffer );
Abuf = uniform( (N*N)*2, -100.0, 100.0, options );
A = new Complex128Array( Abuf.buffer );

alpha = new Complex128( 1.0, 0.0 );
beta = new Complex128( 0.0, 0.0 );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
zgemv( 'row-major', 'no-transpose', N, N, alpha, A, N, 1, 0, x, 1, 0, beta, y, 1, 0 );
if ( isnan( ybuf[ i%N ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( ybuf[ i%N ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var min;
var max;
var N;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
N = pow( 10, i );
f = createBenchmark( N );
bench( pkg+':ndarray:size='+N, f );
}
}

main();
Loading
Loading