|
| 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; |
| 25 | +var Slice = require( '@stdlib/slice/ctor' ); |
| 26 | +var pkg = require( './../package.json' ).name; |
| 27 | +var isSlice = require( './../lib' ); |
| 28 | + |
| 29 | + |
| 30 | +// MAIN // |
| 31 | + |
| 32 | +bench( pkg+'::true', function benchmark( b ) { |
| 33 | + var values; |
| 34 | + var bool; |
| 35 | + var i; |
| 36 | + |
| 37 | + values = [ |
| 38 | + new Slice( 1, 2 ), |
| 39 | + new Slice( 3, 4 ), |
| 40 | + new Slice( 5, 6 ), |
| 41 | + new Slice( 7, 8 ) |
| 42 | + ]; |
| 43 | + |
| 44 | + b.tic(); |
| 45 | + for ( i = 0; i < b.iterations; i++ ) { |
| 46 | + bool = isSlice( values[ i%values.length ] ); |
| 47 | + if ( typeof bool !== 'boolean' ) { |
| 48 | + b.fail( 'should return a boolean' ); |
| 49 | + } |
| 50 | + } |
| 51 | + b.toc(); |
| 52 | + if ( !isBoolean( bool ) ) { |
| 53 | + b.fail( 'should return a boolean' ); |
| 54 | + } |
| 55 | + b.pass( 'benchmark finished' ); |
| 56 | + b.end(); |
| 57 | +}); |
| 58 | + |
| 59 | +bench( pkg+'::false', function benchmark( b ) { |
| 60 | + var values; |
| 61 | + var bool; |
| 62 | + var i; |
| 63 | + |
| 64 | + values = [ |
| 65 | + '5', |
| 66 | + 5, |
| 67 | + NaN, |
| 68 | + true, |
| 69 | + false, |
| 70 | + [], |
| 71 | + {} |
| 72 | + ]; |
| 73 | + |
| 74 | + b.tic(); |
| 75 | + for ( i = 0; i < b.iterations; i++ ) { |
| 76 | + bool = isSlice( values[ i%values.length ] ); |
| 77 | + if ( typeof bool !== 'boolean' ) { |
| 78 | + b.fail( 'should return a boolean' ); |
| 79 | + } |
| 80 | + } |
| 81 | + b.toc(); |
| 82 | + if ( !isBoolean( bool ) ) { |
| 83 | + b.fail( 'should return a boolean' ); |
| 84 | + } |
| 85 | + b.pass( 'benchmark finished' ); |
| 86 | + b.end(); |
| 87 | +}); |
0 commit comments