|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2025 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); |
| 25 | +var baseEmpty = require( '@stdlib/ndarray/base/empty' ); |
| 26 | +var empty = require( '@stdlib/ndarray/empty' ); |
| 27 | +var pkg = require( './../package.json' ).name; |
| 28 | +var toFlippedud = require( './../lib' ); |
| 29 | + |
| 30 | + |
| 31 | +// MAIN // |
| 32 | + |
| 33 | +bench( pkg+'::1d,base', function benchmark( b ) { |
| 34 | + var values; |
| 35 | + var out; |
| 36 | + var i; |
| 37 | + |
| 38 | + values = [ |
| 39 | + baseEmpty( 'float64', [ 2 ], 'row-major' ), |
| 40 | + baseEmpty( 'float32', [ 2 ], 'row-major' ), |
| 41 | + baseEmpty( 'int32', [ 2 ], 'row-major' ), |
| 42 | + baseEmpty( 'complex128', [ 2 ], 'row-major' ), |
| 43 | + baseEmpty( 'generic', [ 2 ], 'row-major' ) |
| 44 | + ]; |
| 45 | + |
| 46 | + b.tic(); |
| 47 | + for ( i = 0; i < b.iterations; i++ ) { |
| 48 | + out = toFlippedud( values[ i%values.length ] ); |
| 49 | + if ( typeof out !== 'object' ) { |
| 50 | + b.fail( 'should return an ndarray' ); |
| 51 | + } |
| 52 | + } |
| 53 | + b.toc(); |
| 54 | + if ( !isndarrayLike( out ) ) { |
| 55 | + b.fail( 'should return an ndarray' ); |
| 56 | + } |
| 57 | + b.pass( 'benchmark finished' ); |
| 58 | + b.end(); |
| 59 | +}); |
| 60 | + |
| 61 | +bench( pkg+'::1d,non-base', function benchmark( b ) { |
| 62 | + var values; |
| 63 | + var out; |
| 64 | + var i; |
| 65 | + |
| 66 | + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ |
| 67 | + |
| 68 | + values = [ |
| 69 | + empty( [ 2 ], { 'dtype': 'float64' } ), |
| 70 | + empty( [ 2 ], { 'dtype': 'float32' } ), |
| 71 | + empty( [ 2 ], { 'dtype': 'int32' } ), |
| 72 | + empty( [ 2 ], { 'dtype': 'complex128' } ), |
| 73 | + empty( [ 2 ], { 'dtype': 'generic' } ) |
| 74 | + ]; |
| 75 | + |
| 76 | + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ |
| 77 | + |
| 78 | + b.tic(); |
| 79 | + for ( i = 0; i < b.iterations; i++ ) { |
| 80 | + out = toFlippedud( values[ i%values.length ] ); |
| 81 | + if ( typeof out !== 'object' ) { |
| 82 | + b.fail( 'should return an ndarray' ); |
| 83 | + } |
| 84 | + } |
| 85 | + b.toc(); |
| 86 | + if ( !isndarrayLike( out ) ) { |
| 87 | + b.fail( 'should return an ndarray' ); |
| 88 | + } |
| 89 | + b.pass( 'benchmark finished' ); |
| 90 | + b.end(); |
| 91 | +}); |
| 92 | + |
| 93 | +bench( pkg+'::2d,base', function benchmark( b ) { |
| 94 | + var values; |
| 95 | + var out; |
| 96 | + var i; |
| 97 | + |
| 98 | + values = [ |
| 99 | + baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), |
| 100 | + baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), |
| 101 | + baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), |
| 102 | + baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), |
| 103 | + baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) |
| 104 | + ]; |
| 105 | + |
| 106 | + b.tic(); |
| 107 | + for ( i = 0; i < b.iterations; i++ ) { |
| 108 | + out = toFlippedud( values[ i%values.length ] ); |
| 109 | + if ( typeof out !== 'object' ) { |
| 110 | + b.fail( 'should return an ndarray' ); |
| 111 | + } |
| 112 | + } |
| 113 | + b.toc(); |
| 114 | + if ( !isndarrayLike( out ) ) { |
| 115 | + b.fail( 'should return an ndarray' ); |
| 116 | + } |
| 117 | + b.pass( 'benchmark finished' ); |
| 118 | + b.end(); |
| 119 | +}); |
| 120 | + |
| 121 | +bench( pkg+'::2d,non-base', function benchmark( b ) { |
| 122 | + var values; |
| 123 | + var out; |
| 124 | + var i; |
| 125 | + |
| 126 | + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ |
| 127 | + |
| 128 | + values = [ |
| 129 | + empty( [ 2, 2 ], { 'dtype': 'float64' } ), |
| 130 | + empty( [ 2, 2 ], { 'dtype': 'float32' } ), |
| 131 | + empty( [ 2, 2 ], { 'dtype': 'int32' } ), |
| 132 | + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), |
| 133 | + empty( [ 2, 2 ], { 'dtype': 'generic' } ) |
| 134 | + ]; |
| 135 | + |
| 136 | + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ |
| 137 | + |
| 138 | + b.tic(); |
| 139 | + for ( i = 0; i < b.iterations; i++ ) { |
| 140 | + out = toFlippedud( values[ i%values.length ] ); |
| 141 | + if ( typeof out !== 'object' ) { |
| 142 | + b.fail( 'should return an ndarray' ); |
| 143 | + } |
| 144 | + } |
| 145 | + b.toc(); |
| 146 | + if ( !isndarrayLike( out ) ) { |
| 147 | + b.fail( 'should return an ndarray' ); |
| 148 | + } |
| 149 | + b.pass( 'benchmark finished' ); |
| 150 | + b.end(); |
| 151 | +}); |
| 152 | + |
| 153 | +bench( pkg+'::3d,base', function benchmark( b ) { |
| 154 | + var values; |
| 155 | + var out; |
| 156 | + var i; |
| 157 | + |
| 158 | + values = [ |
| 159 | + baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), |
| 160 | + baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), |
| 161 | + baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), |
| 162 | + baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), |
| 163 | + baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) |
| 164 | + ]; |
| 165 | + |
| 166 | + b.tic(); |
| 167 | + for ( i = 0; i < b.iterations; i++ ) { |
| 168 | + out = toFlippedud( values[ i%values.length ] ); |
| 169 | + if ( typeof out !== 'object' ) { |
| 170 | + b.fail( 'should return an ndarray' ); |
| 171 | + } |
| 172 | + } |
| 173 | + b.toc(); |
| 174 | + if ( !isndarrayLike( out ) ) { |
| 175 | + b.fail( 'should return an ndarray' ); |
| 176 | + } |
| 177 | + b.pass( 'benchmark finished' ); |
| 178 | + b.end(); |
| 179 | +}); |
| 180 | + |
| 181 | +bench( pkg+'::3d,non-base', function benchmark( b ) { |
| 182 | + var values; |
| 183 | + var out; |
| 184 | + var i; |
| 185 | + |
| 186 | + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ |
| 187 | + |
| 188 | + values = [ |
| 189 | + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), |
| 190 | + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), |
| 191 | + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), |
| 192 | + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), |
| 193 | + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) |
| 194 | + ]; |
| 195 | + |
| 196 | + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ |
| 197 | + |
| 198 | + b.tic(); |
| 199 | + for ( i = 0; i < b.iterations; i++ ) { |
| 200 | + out = toFlippedud( values[ i%values.length ] ); |
| 201 | + if ( typeof out !== 'object' ) { |
| 202 | + b.fail( 'should return an ndarray' ); |
| 203 | + } |
| 204 | + } |
| 205 | + b.toc(); |
| 206 | + if ( !isndarrayLike( out ) ) { |
| 207 | + b.fail( 'should return an ndarray' ); |
| 208 | + } |
| 209 | + b.pass( 'benchmark finished' ); |
| 210 | + b.end(); |
| 211 | +}); |
0 commit comments