<commit_before>/*
 * grunt-phantom-benchmark
 * https://github.com/kevincennis/grunt-phantom-benchmark
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function( grunt ) {

  var phantomjs = require('grunt-lib-phantomjs').init( grunt ),
    path = require('path'),
    fs = require('fs');

  // pass console logs from phantom through to the terminal
  phantomjs.on( 'console', console.log.bind( console ) );

  phantomjs.on( 'benchmark.error', function( e ) {
    throw e;
  });

  // log individual test results
  phantomjs.on( 'benchmark.cycle', function( bench ) {
    var widths = [ 40, 70 ],
      columns = bench.split(' x '),
      str = grunt.log.table( widths, columns );
    grunt.log.ok( str );
  });

  // halt phantom on benchmark.done
  phantomjs.on( 'benchmark.done', function() {
    phantomjs.halt();
  });

  // register the benchmark task
  grunt.registerTask( 'benchmark', 'Benchmarks directories or files',
    function( pattern ) {
    var pathname, done = this.async(), options, files;

    options = this.options({
      inject: []
    });

    options.inject = ([
      path.join( __dirname, '..', '/node_modules/lodash/dist/lodash.js' ),
      path.join( __dirname, '..', '/node_modules/benchmark/benchmark.js' ),
      path.join( __dirname,'scripts/setup.js' )
    ]).concat( options.inject );

    pathname = options.root;
    pattern = pattern || '**/*.js';
    pattern = pathname + '/' + pattern;<commit_msg>BUGFIX: Use `require.resolve` to get path to dependencies, so that task runs correctly if modules aren't located in the local `node_modules` folder<commit_after>/*
 * grunt-phantom-benchmark
 * https://github.com/kevincennis/grunt-phantom-benchmark
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function( grunt ) {

  var phantomjs = require('grunt-lib-phantomjs').init( grunt ),
    path = require('path'),
    fs = require('fs');

  // pass console logs from phantom through to the terminal
  phantomjs.on( 'console', console.log.bind( console ) );

  phantomjs.on( 'benchmark.error', function( e ) {
    throw e;
  });

  // log individual test results
  phantomjs.on( 'benchmark.cycle', function( bench ) {
    var widths = [ 40, 70 ],
      columns = bench.split(' x '),
      str = grunt.log.table( widths, columns );
    grunt.log.ok( str );
  });

  // halt phantom on benchmark.done
  phantomjs.on( 'benchmark.done', function() {
    phantomjs.halt();
  });

  // register the benchmark task
  grunt.registerTask( 'benchmark', 'Benchmarks directories or files',
    function( pattern ) {
    var pathname, done = this.async(), options, files;

    options = this.options({
      inject: []
    });

    options.inject = ([
      require.resolve('lodash'),
      require.resolve('benchmark'),
      path.join( __dirname,'scripts/setup.js' )
    ]).concat( options.inject );

    pathname = options.root;
    pattern = pattern || '**/*.js';
    pattern = pathname + '/' + pattern;
{'fraction_non_alphanumeric': 0.15701119157340354, 'fraction_numerical': 0.005266622778143515, 'mean_word_length': 3.041223404255319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4091448', 'n_tokens_mistral': 1022, 'n_tokens_neox': 931, 'n_words': 242}