|
| 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 Float64Array = require( '@stdlib/array/float64' ); |
| 25 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 26 | +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); |
| 27 | +var pkg = require( './../package.json' ).name; |
| 28 | +var toAccessorArray = require( './../lib' ); |
| 29 | + |
| 30 | + |
| 31 | +// MAIN // |
| 32 | + |
| 33 | +bench( pkg+'::no_accessor_protocol', function benchmark( b ) { |
| 34 | + var values; |
| 35 | + var o; |
| 36 | + var i; |
| 37 | + |
| 38 | + values = [ |
| 39 | + new Float64Array( 10 ), |
| 40 | + new Float64Array( 10 ), |
| 41 | + [ 1, 2, 3 ] |
| 42 | + ]; |
| 43 | + |
| 44 | + b.tic(); |
| 45 | + for ( i = 0; i < b.iterations; i++ ) { |
| 46 | + o = toAccessorArray( values[ i%values.length ] ); |
| 47 | + if ( typeof o !== 'object' ) { |
| 48 | + b.fail( 'should return an object' ); |
| 49 | + } |
| 50 | + } |
| 51 | + b.toc(); |
| 52 | + if ( !isAccessorArray( o ) ) { |
| 53 | + b.fail( 'should return an accessor array' ); |
| 54 | + } |
| 55 | + b.pass( 'benchmark finished' ); |
| 56 | + b.end(); |
| 57 | +}); |
| 58 | + |
| 59 | +bench( pkg+'::accessor_protocol', function benchmark( b ) { |
| 60 | + var values; |
| 61 | + var o; |
| 62 | + var i; |
| 63 | + |
| 64 | + values = [ |
| 65 | + new Complex128Array( 10 ), |
| 66 | + new Complex128Array( 10 ), |
| 67 | + new Complex128Array( 10 ) |
| 68 | + ]; |
| 69 | + |
| 70 | + b.tic(); |
| 71 | + for ( i = 0; i < b.iterations; i++ ) { |
| 72 | + o = toAccessorArray( values[ i%values.length ] ); |
| 73 | + if ( typeof o !== 'object' ) { |
| 74 | + b.fail( 'should return an object' ); |
| 75 | + } |
| 76 | + } |
| 77 | + b.toc(); |
| 78 | + if ( !isAccessorArray( o ) ) { |
| 79 | + b.fail( 'should return an accessor array' ); |
| 80 | + } |
| 81 | + b.pass( 'benchmark finished' ); |
| 82 | + b.end(); |
| 83 | +}); |
0 commit comments