npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-bench

v1.1.0

Published

Run performance benchmark tests

Downloads

4,037

Readme

gulp-bench Build Status

Run performance Benchmark tests. Ported from grunt-benchmark.

Install

$ npm install --save-dev gulp-bench

Usage

The usage syntax below is the same as for grunt-benchmark.

Basic

Setup your benchmark test, e.g. in test.js:

var fibonacci = function(n) {
  return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
};

module.exports = function() {
  fibonacci(10);
};

In your gulpfile:

var gulp = require('gulp');
var benchmark = require('gulp-bench');

gulp.task('default', function () {
	return gulp.src('test.js', {read: false})
		.pipe(benchmark());
});

Run it:

$ gulp
[16:11:01] Running benchmark basic [./test-data/basic.js]...
[16:11:11]    basic x 1,107,255 ops/sec ±0.74% (96 runs sampled)

As well as outputting to console output the plugin stream returns a single file containing the test results in JSON form:

gulp.task('default', function () {
    return gulp.src('test.js', {read: false})
        .pipe(benchmark())
        .pipe(gulp.dest('.'));  /* writes a results file to current folder */   
});

You can modify the results filename and format by supplying plugin options.

Test options

Tests can be configured through futher options:

module.exports = {
  name: 'Timeout (asynchronous)',
  maxTime: 2, /* test should run for max. this no. of seconds */
  defer: true, /* indicates that test is asynchronous */
  onComplete: function() {
    console.log('Hooray!');
  },
  fn: function(deferred) {
    setTimeout(function() {
      deferred.resolve(); 
    }, 500);
  }
};

Test suites

You can compare implementations by constructing a test suite:

var Timer = require('clockmaker').Timer;

module.exports = {
  name: 'Timeout Showdown',
  maxTime: 2,
  tests: {
    'Return immediately (synchronous)': function() {
      return;
    },
    'Timeout: 50ms (asynchronous)': {
      defer: true,
      fn: function(deferred) {
        Timer(deferred.resolve, 50, { this: deferred }).start();
      }
    },
    'Timeout: 100ms (asynchronous)': {
      defer: true,
      fn: function(deferred) {
        Timer(deferred.resolve, 100, { this: deferred }).start();
      }
    }
  }
};

The expected console output for the above test suite will look similar to:

[16:11:01] Running suite Timeout Showdown [./test-data/compare.js]...
[16:11:11]    Sync x 69,826,905 ops/sec ±4.27% (37 runs sampled)
[16:11:26]    Async-50 x 19.64 ops/sec ±0.25% (40 runs sampled)
[16:11:38]    Async-100 x 9.91 ops/sec ±0.17% (23 runs sampled)
[16:11:40] Fastest test is Sync at 3,555,514.2x faster than Async-50

The tests within a suite can also be specified as an array:

var Timer = require('clockmaker').Timer;

module.exports = {
  name: 'Timeout Showdown',
  maxTime: 2,
  tests: [
    {
        name: 'Return immediately (synchronous)',
        fn: function() {
            return;
        }
    },
    {
        name: 'Timeout 50ms (asynchronous)',
        defer: true,
        fn: function(deferred) {
            Timer(deferred.resolve, 50, { this: deferred }).start();
        }
    },
    {
        name: 'Timeout 100ms (asynchronous)',
        defer: true,
        fn: function(deferred) {
            Timer(deferred.resolve, 100, { this: deferred }).start();
        }
    },
  ]
};

Plugin Options

output

Type: String Default: benchmark-results.json

Specifies the name of the file in which to write test results.

outputFormat

Type: String Default: json Values: csv, json

Specifies the format for the output file.

License

MIT - see LICENSE.md