|
| 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 Complex64 = require( '@stdlib/complex/float32' ); |
| 25 | +var pkg = require( './../package.json' ).name; |
| 26 | +var Complex64Array = require( './../lib' ); |
| 27 | + |
| 28 | + |
| 29 | +// MAIN // |
| 30 | + |
| 31 | +bench( pkg+':of', function benchmark( b ) { |
| 32 | + var arr; |
| 33 | + var i; |
| 34 | + |
| 35 | + b.tic(); |
| 36 | + for ( i = 0; i < b.iterations; i++ ) { |
| 37 | + arr = Complex64Array.of(); |
| 38 | + if ( arr.length !== 0 ) { |
| 39 | + b.fail( 'should have length 0' ); |
| 40 | + } |
| 41 | + } |
| 42 | + b.toc(); |
| 43 | + if ( !(arr instanceof Complex64Array) ) { |
| 44 | + b.fail( 'should return an instance' ); |
| 45 | + } |
| 46 | + b.pass( 'benchmark finished' ); |
| 47 | + b.end(); |
| 48 | +}); |
| 49 | + |
| 50 | +bench( pkg+'::interleaved:of:len=5', function benchmark( b ) { |
| 51 | + var buf; |
| 52 | + var arr; |
| 53 | + var i; |
| 54 | + |
| 55 | + buf = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; |
| 56 | + |
| 57 | + b.tic(); |
| 58 | + for ( i = 0; i < b.iterations; i++ ) { |
| 59 | + arr = Complex64Array.of.apply( Complex64Array, buf ); |
| 60 | + if ( arr.length !== 5 ) { |
| 61 | + b.fail( 'should have length 5' ); |
| 62 | + } |
| 63 | + } |
| 64 | + b.toc(); |
| 65 | + if ( !(arr instanceof Complex64Array) ) { |
| 66 | + b.fail( 'should return an instance' ); |
| 67 | + } |
| 68 | + b.pass( 'benchmark finished' ); |
| 69 | + b.end(); |
| 70 | +}); |
| 71 | + |
| 72 | +bench( pkg+'::complex_numbers:of:len=5', function benchmark( b ) { |
| 73 | + var buf; |
| 74 | + var arr; |
| 75 | + var i; |
| 76 | + |
| 77 | + buf = []; |
| 78 | + for ( i = 0; i < 5; i++ ) { |
| 79 | + buf.push( new Complex64( 1.0, 1.0 ) ); |
| 80 | + } |
| 81 | + |
| 82 | + b.tic(); |
| 83 | + for ( i = 0; i < b.iterations; i++ ) { |
| 84 | + arr = Complex64Array.of.apply( Complex64Array, buf ); |
| 85 | + if ( arr.length !== 5 ) { |
| 86 | + b.fail( 'should have length 5' ); |
| 87 | + } |
| 88 | + } |
| 89 | + b.toc(); |
| 90 | + if ( !(arr instanceof Complex64Array) ) { |
| 91 | + b.fail( 'should return an instance' ); |
| 92 | + } |
| 93 | + b.pass( 'benchmark finished' ); |
| 94 | + b.end(); |
| 95 | +}); |
0 commit comments