How to use the benchmark.Suite function in benchmark

To help you get started, we’ve selected a few benchmark examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bramstein / hypher / test / benchmark.js View on Github external
var Benchmark = require('benchmark'),
    Hypher = require('../lib/hypher'),
    suite = new Benchmark.Suite('warm cache'),
    data = require('./data'),
    words = data.words,
    language = data.language,
    assert = require('assert'),
    dictionary = {},
    Hyphenator = require('./Hyphenator.js');

var result = {};

// Create the dictionary of words we're using to test
words.forEach(function (word) {
    var w = word.split('=');
    dictionary[w.join('')] = w;
});

Hyphenator.config({
github arendjr / text-clipper / tests / perf / benchmark / benchmark.js View on Github external
/*var TEST_STRING = (
    //'Dit is allemaal best een mooi verhaal, maar ik geloof er eigenlijk niet zo heel veel van.\n' +
    //'<table><tbody><tr><td>Hoi</td></tr></tbody></table>' +
    '<p>Laten we alvast brainstormen over een aantal van de belangrijkste thema's voor de ' +
    'vergadering die wij hebben over <img src="\'blaat\'"> een paar dagen.of ' +
    '<a rel="noopener noreferrer" href="http://www.nu.nl" class="highlightable">' +
    'http://www.nu.nl</a></p>'
);*/
/*var TEST_STRING = '';
for (var i = 0; i &lt; 100000; i++) {
    TEST_STRING += 'abcdefeghi';
}*/
var TEST_STRING = 'Dit is een string die eigenlijk nog makkelijk past binnen de limiet.';
var TEST_LIMIT = 100;

var suite = new Benchmark.Suite;

// add tests
suite.add('text-clipper', function() {
    clip(TEST_STRING, TEST_LIMIT, { html: true });
})
.add('text-clipper-baseline', function() {
    baseline(TEST_STRING, TEST_LIMIT, { html: true });
})
.add('trim-html', function() {
    trimHtml(TEST_STRING, { limit: TEST_LIMIT });
})
.add('truncate-html', function() {
    truncateHtml(TEST_STRING, TEST_LIMIT);
})
.add('html-truncate', function() {
    htmlTruncate(TEST_STRING, TEST_LIMIT);
github mongodb / js-bson / benchmarks / suite.js View on Github external
candidate2Benchmarks = require('./candidate2/benchmarks');

// Shared functions
var start = function(event) {
  console.log(f('\nStart Suite: %s', this.name).underline.green);
};

var cycle = function(event) {
  console.log(event.target.toString().bold);
};

// Benchmark suites
var legacySuite = new Benchmark.Suite('legacy js parser');
var nativeSuite = new Benchmark.Suite('legacy c++ parser');
var candidate1Suite = new Benchmark.Suite('single buffer allocation with copy parser');
var candidate2Suite = new Benchmark.Suite('faster parser prototype');

// Legacy parser
legacyBenchmarks.forEach(function(bench) {
  legacySuite.add(bench);
});

legacySuite.on('start', start);
legacySuite.on('cycle', cycle);

// C++ Legacy parser
nativeBenchmarks.forEach(function(bench) {
  nativeSuite.add(bench);
});

nativeSuite.on('start', start);
nativeSuite.on('cycle', cycle);
github colyseus / colyseus / test / benchmark / patch.js View on Github external
"use strict";

console.log('benchmark: evaluating a complex patch state')

var Benchmark = require('benchmark')
  , jsonpatch = require('fast-json-patch')
  , fossilDelta = require('fossil-delta')
  , msgpack = require('notepack.io')
  , suite = new Benchmark.Suite()

class PlainState {
  constructor () {
    this.integer = 1;
    this.float = Math.PI
    this.string = "Hello world"
    this.array = [1,2,3,4,5,6,7,8,9,10]
    this.objs = [{hp: 100, x: 0, y: 0}, {hp: 80, x: 10, y: 20}, {hp: 25, x: 8, y: -14}]
    this.boolean = true
    this.null = null
    this.teams = [
      { id: 0, score: 0 },
      { id: 1, score: 0 },
      { id: 2, score: 0 },
      { id: 3, score: 0 }
    ]
github vzhou842 / faster.js / bench / index.js View on Github external
function runBenchmarks(title, nativeSource, compiledSource) {
	const suite = new benchmark.Suite();

	suite.add('native', wrap(nativeSource));
	suite.add('faster.js', wrap(compiledSource));

	suite.on('start', () => console.log('  ' + title));
	suite.on('cycle', event => console.log("    ✓ " + event.target));
	suite.on('complete', function() {
		const slowest = this.filter('slowest')[0];
		const fastest = this.filter('fastest')[0];
		const microsecDelta = ((1000000 / slowest.hz) - (1000000 / fastest.hz)).toFixed(3);
		const percentFaster = (100 * (fastest.hz - slowest.hz) / slowest.hz).toFixed(1);
		console.log(fastest.name + ' is ' + percentFaster + '% faster (' + microsecDelta + 'μs) than ' + slowest.name + '\n');
	});

	suite.run();
}
github 3rd-Eden / useragent / benchmark / regression.js View on Github external
var file = process.argv.slice(2)[0] || 'testcases';

/**
 * Setup the test-files.
 */
var useragentlist = path.join(__dirname, '..', 'test', 'fixtures', file+'.yaml')
  , yammy = yaml.eval(fs.readFileSync(useragentlist).toString()).test_cases
  , testcases = yammy.map(function (test) {
      return test.user_agent_string;
    }).slice(0, 1000)
  , length = testcases.length;

/**
 * Setup the benchmark
 */
var froomfroom = new benchmark.Suite;

froomfroom
.add('useragent latest', function () {
  for (var i = 0; i &lt; length; i++ ) {
    useragent2.parse(testcases[i]);
  }
})
.add('useragent1', function () {
  for (var i = 0; i &lt; length; i++ ) {
    useragent.parse(testcases[i]);
  }
})
.on('cycle', function (event) {
  var details = event.target;

  console.log('Executed benchmark (%s)', details.name);
github Turfjs / turf / packages / turf-tag / bench.js View on Github external
import fs from 'fs';
import Benchmark from 'benchmark';
import tag from './';

var points = JSON.parse(fs.readFileSync('./test/tagPoints.geojson'));
var polygons = JSON.parse(fs.readFileSync('./test/tagPolygons.geojson'));

var suite = new Benchmark.Suite('turf-tag');
suite
  .add('turf-tag',function () {
    tag(points, polygons, 'polyID', 'containingPolyID');
  })
  .on('cycle', function (event) {
    console.log(String(event.target));
  })
  .on('complete', function () {

  })
  .run();
github gregberge / recompact / src / __benchmarks__ / utils.js View on Github external
new Promise(resolve => {
    const mountSuite = new Benchmark.Suite()

    benchs.forEach(({ description, run, onStart }) => {
      mountSuite.add(description, run, { onStart })
    })

    mountSuite
      .on('start', () => {
        const descriptions =
          name || benchs.map(({ description }) => description).join(', ')
        console.log(`Start benchmark ${descriptions}`)
        console.log('-------------------------------')
      })
      .on('cycle', event => {
        console.log(String(event.target))
      })
      .on('complete', function() {
github concordancejs / concordance / perf / lodash-isequal-comparison.js View on Github external
for (let index = 0; index &lt; limit; index++) {
      object2['key' + index] = index
      object3['key' + index] = index
      objects2[index] = { 'num': index }
      objects3[index] = { 'num': index }
      numbers2[index] = index
      numbers3[index] = index
    }
    object3['key' + (limit - 1)] = -1
    objects3[limit - 1].num = -1
    numbers3[limit - 1] = -1
  `
})

suites.push(
  Benchmark.Suite('comparing primitives')
     .add(buildName, {
       'fn': `
         isEqual(1, "1");
         isEqual(1, 1)`,
       'teardown': 'function isEqual(){}'
     })
     .add(otherName, {
       'fn': `
         compare(1, "1");
         compare(1, 1);`,
       'teardown': 'function isEqual(){}'
     })
 )

suites.push(
   Benchmark.Suite('comparing primitives and their object counterparts (edge case)')
github selfrefactor / rambda / benchmark.js View on Github external
update.add("Rambda.update", () => {
    R.update(3, 1, [ 1, 2, 3 ])
  })
  .add("Ramda", () => {
    Ramda.update(3, 1, [ 1, 2, 3 ])
  })
  .on("cycle", event => {
    benchmarks.add(event.target)
  })
  .on("complete", () => {
    benchmarks.log()
  })
  .run()
}

const values = new Benchmark.Suite
options.values = false

if (options.values) {
  const a = {a:1,b:2}
  values.add("Rambda#values", () => {
    R.values(a)
  })
  .add("Ramda", () => {
    Ramda.values(a)
  })
  .add("Lodash", () => {
    _.values(a)
  })
  .on("cycle", event => {
    benchmarks.add(event.target)
  })