diff --git a/lib/node_modules/@stdlib/assert/is-negative-zero/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-negative-zero/benchmark/benchmark.js index f1f29385cc05..3841b6921b58 100644 --- a/lib/node_modules/@stdlib/assert/is-negative-zero/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-negative-zero/benchmark/benchmark.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-new-wrappers, no-undefined, no-empty-function */ +/* eslint-disable no-undefined, no-empty-function */ 'use strict'; diff --git a/lib/node_modules/@stdlib/utils/async/any-by/internal/instrument.js b/lib/node_modules/@stdlib/utils/async/any-by/internal/instrument.js new file mode 100644 index 000000000000..d6c6bd9ceba8 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/async/any-by/internal/instrument.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +// MAIN // + +/** +* Creates a high-resolution timer to measure async operations. +* +* @returns {Function} function to stop the timer and return the duration in milliseconds +*/ +function createTimer() { + var start = process.hrtime(); + + return stop; + + /** + * Stops the timer and returns the elapsed time. + * + * @private + * @returns {number} elapsed time in milliseconds + */ + function stop() { + var diff = process.hrtime( start ); + + // Convert to milliseconds: + return ( diff[ 0 ] * 1e3 ) + ( diff[ 1 ] / 1e6 ); + } +} + + +// EXPORTS // + +module.exports = createTimer; diff --git a/lib/node_modules/@stdlib/utils/async/any-by/lib/factory.js b/lib/node_modules/@stdlib/utils/async/any-by/lib/factory.js index 192ba1923c98..ac22b4f1ba24 100644 --- a/lib/node_modules/@stdlib/utils/async/any-by/lib/factory.js +++ b/lib/node_modules/@stdlib/utils/async/any-by/lib/factory.js @@ -26,6 +26,7 @@ var format = require( '@stdlib/string/format' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); +var createTimer = require( './../internal/instrument.js' ); // MAIN // @@ -129,6 +130,8 @@ function factory( options, predicate ) { * @returns {void} */ function anyByAsync( collection, done ) { + var timer = createTimer(); + if ( !isCollection( collection ) ) { throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); } @@ -146,10 +149,11 @@ function factory( options, predicate ) { * @returns {void} */ function clbk( error, bool ) { + var duration = timer(); if ( error ) { - return done( error, false ); + return done( error, false, duration ); } - done( null, bool ); + done( null, bool, duration ); } } } diff --git a/lib/node_modules/@stdlib/utils/async/any-by/test/test.instrument.js b/lib/node_modules/@stdlib/utils/async/any-by/test/test.instrument.js new file mode 100644 index 000000000000..92959ca85017 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/async/any-by/test/test.instrument.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var createTimer = require( './../internal/instrument.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof createTimer, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a function', function test( t ) { + var stop = createTimer(); + + t.strictEqual( typeof stop, 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the returned function returns a number (elapsed milliseconds)', function test( t ) { + var duration; + var stop = createTimer(); + + setTimeout( onTimeout, 10 ); + + function onTimeout() { + duration = stop(); + + t.strictEqual( typeof duration, 'number', 'returns a number' ); + t.ok( duration >= 0.0, 'returns a non-negative number' ); + t.end(); + } +});