Skip to content

Commit 69ae85b

Browse files
committed
Add remaining missing benchmark files in float64
1 parent a04c190 commit 69ae85b

13 files changed

Lines changed: 1128 additions & 0 deletions
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 format = require( '@stdlib/string/format' );
25+
var pkg = require( './../package.json' ).name;
26+
var Float64Array = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( format( '%s::nonnegative_indices:at', pkg ), function benchmark( b ) {
32+
var arr;
33+
var N;
34+
var v;
35+
var i;
36+
37+
arr = new Float64Array( 10 );
38+
for ( i = 0; i < arr.length; i++ ) {
39+
arr[ i ] = i;
40+
}
41+
N = arr.length;
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
v = arr.at( i%N );
46+
if ( typeof v !== 'number' ) {
47+
b.fail( 'should return a number' );
48+
}
49+
}
50+
b.toc();
51+
if ( typeof v !== 'number' ) {
52+
b.fail( 'should return a number' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
});
57+
58+
bench( format( '%s::negative_indices:at', pkg ), function benchmark( b ) {
59+
var arr;
60+
var N;
61+
var v;
62+
var i;
63+
64+
arr = new Float64Array( 10 );
65+
for ( i = 0; i < arr.length; i++ ) {
66+
arr[ i ] = i;
67+
}
68+
N = arr.length;
69+
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
v = arr.at( -(i%N)-1 );
73+
if ( typeof v !== 'number' ) {
74+
b.fail( 'should return a number' );
75+
}
76+
}
77+
b.toc();
78+
if ( typeof v !== 'number' ) {
79+
b.fail( 'should return a number' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 format = require( '@stdlib/string/format' );
25+
var pkg = require( './../package.json' ).name;
26+
var Float64Array = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( format( '%s:findLast', pkg ), function benchmark( b ) {
32+
var arr;
33+
var v;
34+
var i;
35+
36+
arr = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
v = arr.findLast( predicate );
41+
if ( typeof v !== 'number' ) {
42+
b.fail( 'should return a number' );
43+
}
44+
}
45+
b.toc();
46+
if ( typeof v !== 'number' ) {
47+
b.fail( 'should return a number' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
52+
function predicate( v ) {
53+
return ( v > 0.0 );
54+
}
55+
});
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 pow = require( '@stdlib/math/base/special/pow' );
25+
var format = require( '@stdlib/string/format' );
26+
var pkg = require( './../package.json' ).name;
27+
var Float64Array = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Predicate function.
34+
*
35+
* @private
36+
* @param {number} value - array element
37+
* @param {NonNegativeInteger} idx - array element index
38+
* @param {Float64Array} arr - array instance
39+
* @returns {boolean} boolean indicating whether a value passes a test
40+
*/
41+
function predicate( value ) {
42+
return ( value < 0.0 );
43+
}
44+
45+
/**
46+
* Creates a benchmark function.
47+
*
48+
* @private
49+
* @param {PositiveInteger} len - array length
50+
* @returns {Function} benchmark function
51+
*/
52+
function createBenchmark( len ) {
53+
var arr;
54+
var i;
55+
56+
arr = new Float64Array( len );
57+
arr[ 0 ] = -1.0;
58+
for ( i = 1; i < len; i++ ) {
59+
arr[ i ] = i;
60+
}
61+
62+
return benchmark;
63+
64+
/**
65+
* Benchmark function.
66+
*
67+
* @private
68+
* @param {Benchmark} b - benchmark instance
69+
*/
70+
function benchmark( b ) {
71+
var v;
72+
var i;
73+
74+
b.tic();
75+
for ( i = 0; i < b.iterations; i++ ) {
76+
v = arr.findLast( predicate );
77+
if ( typeof v !== 'number' ) {
78+
b.fail( 'should return a number' );
79+
}
80+
}
81+
b.toc();
82+
if ( typeof v !== 'number' ) {
83+
b.fail( 'should return a number' );
84+
}
85+
b.pass( 'benchmark finished' );
86+
b.end();
87+
}
88+
}
89+
90+
91+
// MAIN //
92+
93+
/**
94+
* Main execution sequence.
95+
*
96+
* @private
97+
*/
98+
function main() {
99+
var len;
100+
var min;
101+
var max;
102+
var f;
103+
var i;
104+
105+
min = 1; // 10^min
106+
max = 6; // 10^max
107+
108+
for ( i = min; i <= max; i++ ) {
109+
len = pow( 10, i );
110+
f = createBenchmark( len );
111+
bench( format( '%s:findLast:len=%d', pkg, len ), f );
112+
}
113+
}
114+
115+
main();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
25+
var format = require( '@stdlib/string/format' );
26+
var pkg = require( './../package.json' ).name;
27+
var Float64Array = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( format( '%s:findLastIndex', pkg ), function benchmark( b ) {
33+
var arr;
34+
var idx;
35+
var i;
36+
37+
arr = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
idx = arr.findLastIndex( predicate );
42+
if ( typeof idx !== 'number' ) {
43+
b.fail( 'should return an integer' );
44+
}
45+
}
46+
b.toc();
47+
if ( !isInteger( idx ) ) {
48+
b.fail( 'should return an integer' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
53+
function predicate( v ) {
54+
return ( v > 0.0 );
55+
}
56+
});

0 commit comments

Comments
 (0)