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