gulp-bench

Run performance benchmark tests

gulp-bench

Run performance Benchmarktests. 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: StringDefault: benchmark-results.json

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

outputFormat

Type: StringDefault: jsonValues: csv, json

Specifies the format for the outputfile.

License

MIT - see LICENSE.md

HomePage

https://github.com/hiddentao/gulp-bench

Repository

https://github.com/hiddentao/gulp-bench.git


上一篇:clockmaker
下一篇:enum

相关推荐

  • 简单谈谈gulp-changed插件

    前言 gulpchanged插件的作用,是用来过滤未被修改过的文件,只有修改后的文件才能通过管道。这样做的好处时,只处理修改后的文件,减少后续程序的执行时间。 根据官方给出的例子: 检测SR...

    3 年前
  • 用gulp构建一个简单常用的的原生环境

    gulp作为一个自动化构建工具,在前端开发中大大的提高了开发效率,前端开发者们可以利用他减少许多繁复无脑的操作。 这里简单构建一个小环境,就可以在以后的学习中,直接新建各种test.html测试我们新...

    2 年前
  • 用gulp实现传统的多页面自动化构建,一句命令行完成混淆压缩

    工作的项目,摄像头的设置页面,要求整站大小只能在100k作用,也就是说vue之类的框架,jquery库这些最好不要用,我们就用js原生语言写,并且每次写完要整站都要压缩混淆再上传,考虑到浏览器文件缓存...

    4 个月前
  • 整理笔记:前端工程构建工具gulp篇

    gulp ,基于 NodeJS 的项目,自动化构建的工具增强你的工作流程! 一、工作原理 前端构建工具,gulp是基于Nodejs,自动化地完成 javascript、coffee、sass、less...

    1 个月前
  • 工具 之 gulp使用

    timg.jpeg(/public/upload/133329767e0a2fa7fa26c36bf41ec8e0) 介绍 gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器...

    2 个月前
  • 如何能在每一gulpfile吞重新开始改变?

    jfmercercoool(https://stackoverflow.com/users/754842/jfmercer)提出了一个问题:How can Gulp be restarted upon...

    2 年前
  • 如何用上webpack/gulp/rollup,搭建一个基于Vue的UI库脚手架

    目标:搭建一个基于vue的ui脚手架,库的加载方式支持script标签,模块化加载,组件引入方式支持按需加载和全量加载。 脚手架链接 目录、文件约定 完整的一个组件库脚手架不但应该有合理的组件存...

    5 个月前
  • 如何保存流到Gulp.js多个目的地吗?

    Konstantin Tarkus(https://stackoverflow.com/users/82686/konstantintarkus)提出了一个问题:How to save a strea...

    2 年前
  • 如何gulp压缩,丑化代码

    为什么使用 最近在迭代公司的项目,发现项目有如下缺点: 1. 代码没有压缩,js文件,内存大,放在服务器上占空间; 2. 源代码没有混淆或者丑化处理,本公司的程序员写出来的代码和高质量逻辑容...

    1 年前
  • 大口大口的gulp.watch不引发新的或已删除的文件?

    gremo(https://stackoverflow.com/users/220180/gremo)提出了一个问题:Gulps gulp.watch not triggered for new or...

    2 年前

官方社区

扫码加入 JavaScript 社区