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