<commit_before>var _ = require('underscore'),
    BenchWarmer = require('./util/benchwarmer'),
    templates = require('./templates'),

    eco, dust, Handlebars, Mustache, eco;

try {
  dust = require("dustjs-linkedin");
} catch (err) { /* NOP */ }

try {
  Mustache = require("mustache");
} catch (err) { /* NOP */ }

try {
  eco = require("eco");
} catch (err) { /* NOP */ }

function error() {
  throw new Error("EWOT");
}

function makeSuite(warmer, name, template) {
  warmer.suite(name, function(bench) {
    // Create aliases to minimize any impact from having to walk up the closure tree.
    var templateName = name,

        context = template.context,
        partials = template.partials;

    var handlebar = Handlebars.compile(template.handlebars),
        options = {helpers: template.helpers};
    _.each(template.partials && template.partials.handlebars, function(partial, name) {
      Handlebars.registerPartial(name, partial);
    });

    bench("handlebars", function() {
      handlebar(context, options);
    });

    if (dust) {
      if (template.dust) {
        dust.loadSource(dust.compile(template.dust, templateName));

        bench("dust", function() {
          dust.render(templateName, context, function(err, out) { });
        });
      } else {
        bench('dust', error);
      }
    }

    if (eco) {
      if (template.eco) {
        var ecoTemplate = eco(template.eco);

        bench("eco", function() {
          ecoTemplate(context);
        });
      } else {
        bench("eco", error);
      }
    }

    if (Mustache) {
      var mustacheSource = template.mustache,
          mustachePartials = partials && partials.mustache;

      if (mustacheSource) {
        bench("mustache", function() {
          Mustache.to_html(mustacheSource, context, mustachePartials);
        });
      } else {
        bench("mustache", error);
      }
    }
  });
}

module.exports = function(grunt, callback) {
  // Deferring load incase we are being run inline with the grunt build
  Handlebars = require('../lib/handlebars');

  var warmer = new BenchWarmer();

  _.each(templates, function(template, name) {
    if (!template.handlebars) {
      return;
    }

    makeSuite(warmer, name, template);
  });

  warmer.bench(function() {
    callback && callback(warmer.times);
  });
};<commit_msg>Add handlebars-only and grep metrics options<commit_after>var _ = require('underscore'),
    BenchWarmer = require('./util/benchwarmer'),
    templates = require('./templates'),

    eco, dust, Handlebars, Mustache, eco;

try {
  dust = require("dustjs-linkedin");
} catch (err) { /* NOP */ }

try {
  Mustache = require("mustache");
} catch (err) { /* NOP */ }

try {
  eco = require("eco");
} catch (err) { /* NOP */ }

function error() {
  throw new Error("EWOT");
}

function makeSuite(warmer, name, template, handlebarsOnly) {
  warmer.suite(name, function(bench) {
    // Create aliases to minimize any impact from having to walk up the closure tree.
    var templateName = name,

        context = template.context,
        partials = template.partials;

    var handlebar = Handlebars.compile(template.handlebars),
        options = {helpers: template.helpers};
    _.each(template.partials && template.partials.handlebars, function(partial, name) {
      Handlebars.registerPartial(name, partial);
    });

    bench("handlebars", function() {
      handlebar(context, options);
    });

    if (handlebarsOnly) {
      return;
    }

    if (dust) {
      if (template.dust) {
        dust.loadSource(dust.compile(template.dust, templateName));

        bench("dust", function() {
          dust.render(templateName, context, function(err, out) { });
        });
      } else {
        bench('dust', error);
      }
    }

    if (eco) {
      if (template.eco) {
        var ecoTemplate = eco(template.eco);

        bench("eco", function() {
          ecoTemplate(context);
        });
      } else {
        bench("eco", error);
      }
    }

    if (Mustache) {
      var mustacheSource = template.mustache,
          mustachePartials = partials && partials.mustache;

      if (mustacheSource) {
        bench("mustache", function() {
          Mustache.to_html(mustacheSource, context, mustachePartials);
        });
      } else {
        bench("mustache", error);
      }
    }
  });
}

module.exports = function(grunt, callback) {
  // Deferring load incase we are being run inline with the grunt build
  Handlebars = require('../lib/handlebars');

  var warmer = new BenchWarmer();

  var handlebarsOnly = grunt.option('handlebars-only'),
      grep = grunt.option('grep');
  if (grep) {
    grep = new RegExp(grep);
  }

  _.each(templates, function(template, name) {
    if (!template.handlebars || (grep && !grep.test(name))) {
      return;
    }

    makeSuite(warmer, name, template, handlebarsOnly);
  });

  warmer.bench(function() {
    callback && callback(warmer.times);
  });
};
{'fraction_non_alphanumeric': 0.14707667408456404, 'fraction_numerical': 0.0, 'mean_word_length': 2.6487084870848707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6025740', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1499, 'n_words': 334}