Skip to content
Open
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
83 changes: 83 additions & 0 deletions lib/node_modules/@stdlib/array/float64/benchmark/benchmark.at.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Float64Array = require( './../lib' );


// MAIN //

bench( format( '%s::nonnegative_indices:at', pkg ), function benchmark( b ) {
var arr;
var N;
var v;
var i;

arr = new Float64Array( 10 );
for ( i = 0; i < arr.length; i++ ) {
arr[ i ] = i;
}
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.at( i%N );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::negative_indices:at', pkg ), function benchmark( b ) {
var arr;
var N;
var v;
var i;

arr = new Float64Array( 10 );
for ( i = 0; i < arr.length; i++ ) {
arr[ i ] = i;
}
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.at( -(i%N)-1 );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Float64Array = require( './../lib' );


// MAIN //

bench( format( '%s:findLast', pkg ), function benchmark( b ) {
var arr;
var v;
var i;

arr = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.findLast( predicate );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();

function predicate( v ) {
return ( v > 0.0 );
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Float64Array = require( './../lib' );


// FUNCTIONS //

/**
* Predicate function.
*
* @private
* @param {number} value - array element
* @param {NonNegativeInteger} idx - array element index
* @param {Float64Array} arr - array instance
* @returns {boolean} boolean indicating whether a value passes a test
*/
function predicate( value ) {
return ( value < 0.0 );
}

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr;
var i;

arr = new Float64Array( len );
arr[ 0 ] = -1.0;
for ( i = 1; i < len; i++ ) {
arr[ i ] = i;
}

return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.findLast( predicate );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

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

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

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:findLast:len=%d', pkg, len ), f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Float64Array = require( './../lib' );


// MAIN //

bench( format( '%s:findLastIndex', pkg ), function benchmark( b ) {
var arr;
var idx;
var i;

arr = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = arr.findLastIndex( predicate );
if ( typeof idx !== 'number' ) {
b.fail( 'should return an integer' );
}
}
b.toc();
if ( !isInteger( idx ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();

function predicate( v ) {
return ( v > 0.0 );
}
});
Loading
Loading