|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2023 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 uniform = require( '@stdlib/random/base/uniform' ).factory; |
| 25 | +var isnan = require( '@stdlib/math/base/assert/is-nan' ); |
| 26 | +var pow = require( '@stdlib/math/base/special/pow' ); |
| 27 | +var floor = require( '@stdlib/math/base/special/floor' ); |
| 28 | +var filled3dBy = require( '@stdlib/array/base/filled3d-by' ); |
| 29 | +var numel = require( '@stdlib/ndarray/base/numel' ); |
| 30 | +var pkg = require( './../package.json' ).name; |
| 31 | +var fliplr3d = require( './../lib' ); |
| 32 | + |
| 33 | + |
| 34 | +// FUNCTIONS // |
| 35 | + |
| 36 | +/** |
| 37 | +* Creates a benchmark function. |
| 38 | +* |
| 39 | +* @private |
| 40 | +* @param {PositiveIntegerArray} shape - array shape |
| 41 | +* @returns {Function} benchmark function |
| 42 | +*/ |
| 43 | +function createBenchmark( shape ) { |
| 44 | + var x = filled3dBy( shape, uniform( -100.0, 100.0 ) ); |
| 45 | + return benchmark; |
| 46 | + |
| 47 | + /** |
| 48 | + * Benchmark function. |
| 49 | + * |
| 50 | + * @private |
| 51 | + * @param {Benchmark} b - benchmark instance |
| 52 | + */ |
| 53 | + function benchmark( b ) { |
| 54 | + var out; |
| 55 | + var i0; |
| 56 | + var i1; |
| 57 | + var i2; |
| 58 | + var i; |
| 59 | + |
| 60 | + b.tic(); |
| 61 | + for ( i = 0; i < b.iterations; i++ ) { |
| 62 | + out = fliplr3d( x ); |
| 63 | + i2 = i % shape[ 0 ]; |
| 64 | + i1 = i % shape[ 1 ]; |
| 65 | + i0 = i % shape[ 2 ]; |
| 66 | + if ( isnan( out[ i2 ][ i1 ][ i0 ] ) ) { |
| 67 | + b.fail( 'should not return NaN' ); |
| 68 | + } |
| 69 | + } |
| 70 | + b.toc(); |
| 71 | + |
| 72 | + i2 = i % shape[ 0 ]; |
| 73 | + i1 = i % shape[ 1 ]; |
| 74 | + i0 = i % shape[ 2 ]; |
| 75 | + if ( isnan( out[ i2 ][ i1 ][ i0 ] ) ) { |
| 76 | + b.fail( 'should not return NaN' ); |
| 77 | + } |
| 78 | + b.pass( 'benchmark finished' ); |
| 79 | + b.end(); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | +// MAIN // |
| 85 | + |
| 86 | +/** |
| 87 | +* Main execution sequence. |
| 88 | +* |
| 89 | +* @private |
| 90 | +*/ |
| 91 | +function main() { |
| 92 | + var min; |
| 93 | + var max; |
| 94 | + var sh; |
| 95 | + var N; |
| 96 | + var f; |
| 97 | + var i; |
| 98 | + |
| 99 | + min = 1; // 10^min |
| 100 | + max = 6; // 10^max |
| 101 | + |
| 102 | + for ( i = min; i <= max; i++ ) { |
| 103 | + N = floor( pow( pow( 10, i ), 1.0/3.0 ) ); |
| 104 | + sh = [ N, N, N ]; |
| 105 | + f = createBenchmark( sh ); |
| 106 | + bench( pkg+'::equidimensional:size='+numel( sh ), f ); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +main(); |
0 commit comments