|
| 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 Uint32Array = require( '@stdlib/array/uint32' ); |
| 25 | +var isnan = require( '@stdlib/math/base/assert/is-nan' ); |
| 26 | +var minstd = require( '@stdlib/random/base/minstd-shuffle' ); |
| 27 | +var pkg = require( './../package.json' ).name; |
| 28 | +var factory = require( './../lib' ).factory; |
| 29 | + |
| 30 | + |
| 31 | +// MAIN // |
| 32 | + |
| 33 | +bench( pkg+':factory', function benchmark( b ) { |
| 34 | + var f; |
| 35 | + var i; |
| 36 | + |
| 37 | + b.tic(); |
| 38 | + for ( i = 0; i < b.iterations; i++ ) { |
| 39 | + f = factory(); |
| 40 | + if ( typeof f !== 'function' ) { |
| 41 | + b.fail( 'should return a function' ); |
| 42 | + } |
| 43 | + } |
| 44 | + b.toc(); |
| 45 | + if ( isnan( f() ) ) { |
| 46 | + b.fail( 'should not return NaN' ); |
| 47 | + } |
| 48 | + b.pass( 'benchmark finished' ); |
| 49 | + b.end(); |
| 50 | +}); |
| 51 | + |
| 52 | +bench( pkg+':factory:seed=<integer>', function benchmark( b ) { |
| 53 | + var opts; |
| 54 | + var f; |
| 55 | + var i; |
| 56 | + |
| 57 | + opts = { |
| 58 | + 'seed': 1 |
| 59 | + }; |
| 60 | + |
| 61 | + b.tic(); |
| 62 | + for ( i = 0; i < b.iterations; i++ ) { |
| 63 | + opts.seed += i; |
| 64 | + f = factory( opts ); |
| 65 | + if ( typeof f !== 'function' ) { |
| 66 | + b.fail( 'should return a function' ); |
| 67 | + } |
| 68 | + } |
| 69 | + b.toc(); |
| 70 | + if ( isnan( f() ) ) { |
| 71 | + b.fail( 'should not return NaN' ); |
| 72 | + } |
| 73 | + b.pass( 'benchmark finished' ); |
| 74 | + b.end(); |
| 75 | +}); |
| 76 | + |
| 77 | +bench( pkg+':factory:seed=<array>', function benchmark( b ) { |
| 78 | + var seed; |
| 79 | + var opts; |
| 80 | + var f; |
| 81 | + var i; |
| 82 | + |
| 83 | + opts = {}; |
| 84 | + |
| 85 | + seed = new Uint32Array( 10 ); |
| 86 | + for ( i = 0; i < seed.length; i++ ) { |
| 87 | + seed[ i ] = minstd(); |
| 88 | + } |
| 89 | + opts.seed = seed; |
| 90 | + |
| 91 | + b.tic(); |
| 92 | + for ( i = 0; i < b.iterations; i++ ) { |
| 93 | + opts.seed[ 0 ] = i + 1; |
| 94 | + f = factory( opts ); |
| 95 | + if ( typeof f !== 'function' ) { |
| 96 | + b.fail( 'should return a function' ); |
| 97 | + } |
| 98 | + } |
| 99 | + b.toc(); |
| 100 | + if ( isnan( f() ) ) { |
| 101 | + b.fail( 'should not return NaN' ); |
| 102 | + } |
| 103 | + b.pass( 'benchmark finished' ); |
| 104 | + b.end(); |
| 105 | +}); |
0 commit comments