|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2018 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 Complex64 = require( '@stdlib/complex/float32' ); |
| 26 | +var pkg = require( './../package.json' ).name; |
| 27 | +var Complex64Array = 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 | + var arr; |
| 41 | + var buf; |
| 42 | + var i; |
| 43 | + |
| 44 | + arr = []; |
| 45 | + for ( i = 0; i < len+1; i++ ) { |
| 46 | + arr.push( new Complex64( i, i ) ); |
| 47 | + } |
| 48 | + arr = new Complex64Array( arr ); |
| 49 | + buf = arr.buffer; |
| 50 | + |
| 51 | + return benchmark; |
| 52 | + |
| 53 | + /** |
| 54 | + * Benchmark function. |
| 55 | + * |
| 56 | + * @private |
| 57 | + * @param {Benchmark} b - benchmark instance |
| 58 | + */ |
| 59 | + function benchmark( b ) { |
| 60 | + var i; |
| 61 | + |
| 62 | + b.tic(); |
| 63 | + for ( i = 0; i < b.iterations; i++ ) { |
| 64 | + buf[ 0 ] = i; |
| 65 | + arr.copyWithin( 1, 0 ); |
| 66 | + if ( buf[ 0 ] !== i ) { |
| 67 | + b.fail( 'unexpected result' ); |
| 68 | + } |
| 69 | + } |
| 70 | + b.toc(); |
| 71 | + if ( buf[ 0 ] !== buf[ 0 ] ) { |
| 72 | + b.fail( 'should not be NaN' ); |
| 73 | + } |
| 74 | + b.pass( 'benchmark finished' ); |
| 75 | + b.end(); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | + |
| 80 | +// MAIN // |
| 81 | + |
| 82 | +/** |
| 83 | +* Main execution sequence. |
| 84 | +* |
| 85 | +* @private |
| 86 | +*/ |
| 87 | +function main() { |
| 88 | + var len; |
| 89 | + var min; |
| 90 | + var max; |
| 91 | + var f; |
| 92 | + var i; |
| 93 | + |
| 94 | + min = 1; // 10^min |
| 95 | + max = 6; // 10^max |
| 96 | + |
| 97 | + for ( i = min; i <= max; i++ ) { |
| 98 | + len = pow( 10, i ); |
| 99 | + f = createBenchmark( len ); |
| 100 | + bench( pkg+':len='+len, f ); |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +main(); |
0 commit comments