|
| 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 randu = require( '@stdlib/random/base/randu' ); |
| 25 | +var pkg = require( './../package.json' ).name; |
| 26 | +var incrnanmmin = require( './../lib' ); |
| 27 | + |
| 28 | + |
| 29 | +// MAIN // |
| 30 | + |
| 31 | +bench( pkg, function benchmark( b ) { |
| 32 | + var f; |
| 33 | + var i; |
| 34 | + b.tic(); |
| 35 | + for ( i = 0; i < b.iterations; i++ ) { |
| 36 | + f = incrnanmmin( (i%5)+1 ); |
| 37 | + if ( typeof f !== 'function' ) { |
| 38 | + b.fail( 'should return a function' ); |
| 39 | + } |
| 40 | + } |
| 41 | + b.toc(); |
| 42 | + if ( typeof f !== 'function' ) { |
| 43 | + b.fail( 'should return a function' ); |
| 44 | + } |
| 45 | + b.pass( 'benchmark finished' ); |
| 46 | + b.end(); |
| 47 | +}); |
| 48 | + |
| 49 | +bench( pkg+'::accumulator', function benchmark( b ) { |
| 50 | + var acc; |
| 51 | + var v; |
| 52 | + var i; |
| 53 | + |
| 54 | + acc = incrnanmmin( 5 ); |
| 55 | + |
| 56 | + b.tic(); |
| 57 | + for ( i = 0; i < b.iterations; i++ ) { |
| 58 | + v = acc( randu() ); |
| 59 | + if ( v !== v ) { |
| 60 | + b.fail( 'should not return NaN' ); |
| 61 | + } |
| 62 | + } |
| 63 | + b.toc(); |
| 64 | + if ( v !== v ) { |
| 65 | + b.fail( 'should not return NaN' ); |
| 66 | + } |
| 67 | + b.pass( 'benchmark finished' ); |
| 68 | + b.end(); |
| 69 | +}); |
0 commit comments