|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 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 isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); |
| 26 | +var pkg = require( './../package.json' ).name; |
| 27 | +var empty = require( './../lib' ); |
| 28 | + |
| 29 | + |
| 30 | +// FUNCTIONS // |
| 31 | + |
| 32 | +/** |
| 33 | +* Creates a benchmark function. |
| 34 | +* |
| 35 | +* @private |
| 36 | +* @param {PositiveInteger} len - array length |
| 37 | +* @returns {Function} benchmark function |
| 38 | +*/ |
| 39 | +function createBenchmark( len ) { |
| 40 | + return benchmark; |
| 41 | + |
| 42 | + /** |
| 43 | + * Benchmark function. |
| 44 | + * |
| 45 | + * @private |
| 46 | + * @param {Benchmark} b - benchmark instance |
| 47 | + */ |
| 48 | + function benchmark( b ) { |
| 49 | + var arr; |
| 50 | + var i; |
| 51 | + |
| 52 | + b.tic(); |
| 53 | + for ( i = 0; i < b.iterations; i++ ) { |
| 54 | + arr = empty( len, 'bool' ); |
| 55 | + if ( arr.length !== len ) { |
| 56 | + b.fail( 'unexpected length' ); |
| 57 | + } |
| 58 | + } |
| 59 | + b.toc(); |
| 60 | + if ( !isTypedArrayLike( arr ) ) { |
| 61 | + b.fail( 'should return a typed array' ); |
| 62 | + } |
| 63 | + b.pass( 'benchmark finished' ); |
| 64 | + b.end(); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | + |
| 69 | +// MAIN // |
| 70 | + |
| 71 | +/** |
| 72 | +* Main execution sequence. |
| 73 | +* |
| 74 | +* @private |
| 75 | +*/ |
| 76 | +function main() { |
| 77 | + var len; |
| 78 | + var min; |
| 79 | + var max; |
| 80 | + var f; |
| 81 | + var i; |
| 82 | + |
| 83 | + min = 1; // 10^min |
| 84 | + max = 6; // 10^max |
| 85 | + |
| 86 | + for ( i = min; i <= max; i++ ) { |
| 87 | + len = pow( 10, i ); |
| 88 | + f = createBenchmark( len ); |
| 89 | + bench( pkg+':dtype=bool,len='+len, f ); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +main(); |
0 commit comments