Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 bench = require( '@stdlib/bench' );
var pkg = require( './../package.json' ).name;
var waterfall = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var fcns;
var i;

fcns = [ foo, bar, fun ];

i = 0;
b.tic();

return next();

function next( error ) {
i += 1;
if ( error ) {
b.fail( 'should not return an error' );
}
if ( i <= b.iterations ) {
return waterfall( fcns, done );
}
b.toc();
b.pass( 'benchmark finished' );
b.end();
}

function foo( clbk ) {
setTimeout( onTimeout, 0 );
function onTimeout() {
clbk( null, 'beep' );
}
}

function bar( str, clbk ) {
setTimeout( onTimeout, 0 );
function onTimeout() {
clbk( null, str + ' boop' );
}
}

function fun( str, clbk ) {
setTimeout( onTimeout, 0 );
function onTimeout() {
clbk( null );
}
}

function done( error ) {
if ( error ) {
next( error );
return;
}
next();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
],
"main": "./lib",
"directories": {
"benchmark": "./benchmark",
"doc": "./docs",
"example": "./examples",
"lib": "./lib",
Expand Down
Loading