How to use the benchmark.runInContext 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 Hypercubed / chuhai / src / index.js View on Github external
/* global window */

const Promise = require('bluebird');
const fnName = require('fn-name');
const debug = require('debug')('chuhai');

// require('loud-rejection/api')(process);

let benchmark = require('benchmark');

/* istanbul ignore next */
if (typeof window !== 'undefined') {
  const _ = require('lodash');
  const process = require('process');
  benchmark = benchmark.runInContext({_, process});
  window.Benchmark = benchmark;
}

// Promise.longStackTraces();

const reporterKey = process.env.REPORTER || 'markdown';

const reporters = {
  markdown: require('./reporters/markdown')
};

const reporter = reporters[reporterKey];

function noop() {}

// maybe usefull later
github almin / almin / perf / benchmark / src / index.js View on Github external
// MIT © 2017 azu
"use strict";
const task = require("./task");
const process = require("process");
const _ = require("lodash");
let Benchmark = require("benchmark");
Benchmark = Benchmark.runInContext({ _: _, process: process });
const Suite = Benchmark.Suite;
// workaround for browser
// https://github.com/bestiejs/benchmark.js/issues/128
if (typeof window == "object") {
    window.Benchmark = Benchmark;
    window.Suite = Suite;
}
/**
 * @param {Object} AlminVeesions
 * @param {function(benchmark: Object}} done
 */
module.exports = function(AlminVersions, done) {
    const suite = new Suite();
    // randomize for equality
    _.shuffle(Object.keys(AlminVersions)).forEach(version => {
        suite.add(
github Rowno / react-benchmark / lib / client.js View on Github external
import benchmark from 'benchmark'
import lodash from 'lodash'
import ReactDOM from 'react-dom'
import testComponent from 'react-benchmark-test-component' // eslint-disable-line import/no-unresolved

// Hack to make benchmark work via webpack
const Benchmark = benchmark.runInContext({_: lodash})
window.Benchmark = Benchmark

// Render an instance in the DOM before running the benchmark to make debugging easier
const container = document.createElement('div')
ReactDOM.render(testComponent(), container)
document.body.append(container)

const bench = new Benchmark({
  defer: true,
  async: true,
  fn(deferred) {
    const container = document.createElement('div')
    ReactDOM.render(testComponent(), container, () => {
      deferred.resolve()
    })
  },
github Hypercubed / EventsSpeedTests / benchmarks / suite.js View on Github external
var process = require('process');
var benchmark = require('benchmark');
var _ = require('lodash');

if (typeof window !== 'undefined') {
  benchmark = benchmark.runInContext({_, process});
  window.Benchmark = benchmark;
}

module.exports = function suite(name) {
  var suite = new benchmark.Suite(name);

  suite
    .on('cycle', function cycle(e) {
      if (!e.target.aborted) {
        console.log('    ' + String(e.target));
      }
    })
    .on('error', function (e) {
      console.log(String(e.target.name) + ' ' + String(e.target.error));
    })
    .on('complete', function () {
github jscodec / jsvpx / benchmarks / benchmark.js View on Github external
var process = require('process');
var Benchmark = require('benchmark');

var blankFormat = {
    videoFormat: {
        cropLeft: null,
        cropTop: null,
        cropWidth: null,
        cropHeight: null,
        displayWidth: null,
        displayHeight: null
    }
};

var Benchmark = require('benchmark');
Benchmark = Benchmark.runInContext({_: _, process: process});
window.Benchmark = Benchmark;

var emscriptenDecoder = new OGVDecoderVideoVP8(blankFormat);
emscriptenDecoder.init(function () {});

var ivf = require('jsivf');
var jsvpx = require('../build-templates/OgVVideoDecoder.js');

var benchmarkOptions = {
    maxTime: 1000000,
    async: true
};


var suite = new Benchmark.Suite(benchmarkOptions);
var vectorFolder = '../vp8-test-vectors/';
github mapbox / earcut / index_browser.js View on Github external
import("./earcut").then((module) => {
    const earcut_wasm = module.earcut_flat;

    const samples = {
        'typical OSM building': earcut.flatten(require('./test/fixtures/building.json')),
        'dude shape': earcut.flatten(require('./test/fixtures/dude.json')),
        'complex OSM water': earcut.flatten(require('./test/fixtures/water.json'))
    };

    const benchmark = require('benchmark');
    const Benchmark = benchmark.runInContext({ _, process });
    window.Benchmark = Benchmark;

    setTimeout(() => {
        for (const name in samples) {
            const {vertices, holes} = samples[name];
            const verticesArray = Float64Array.from(vertices);
            const holesArray = Uint32Array.from(holes);
            new Benchmark.Suite()
                .add(`JS ${name} (${vertices.length / 2} vertices):`, function () {
                    earcut(vertices, holes);
                })
                .add(`rust WASM ${name} (${vertices.length / 2} vertices):`, function () {
                    earcut_wasm(verticesArray, holesArray);
                })
                .add(`embind WASM ${name} (${vertices.length / 2} vertices):`, function () {
                    embind_earcut(verticesArray, holesArray);
github snapwich / fun-hooks / benchmark.js View on Github external
var _ = require("lodash");
var process = require("process");
var benchmark = require("benchmark");
var Benchmark = benchmark.runInContext({_, process});
if (typeof window !== "undefined") {
  window.Benchmark = Benchmark;
}
var hookNoEval = require("./index.js")();
var hookEval = require("./index.eval")();

var addHooks = new Benchmark.Suite("add hooks");

var hook = function(next, a, b) {
  next(a + 1, b + 1);
};

var hookedEval;
var hookedNoEval;

addHooks
github MichaReiser / speedy.js / packages / benchmark / run-benchmarks.js View on Github external
"use strict";

const benchmarkImport = require("benchmark");
const _ = require("lodash");
const platform = require("platform");
const deepEqual = require("deep-equal");

const Benchmark = window.Benchmark = benchmarkImport.runInContext( { _: _, platform: platform });

const TEST_CASES = {
    "monteCarlo": {
        args: [
            {
                investmentAmount: 620000,
                numRuns: 10000,
                numYears: 15,
                performance: 0.0340000,
                projects: [
                    {
                        startYear: 0,
                        totalAmount: 10000
                    }, {
                        startYear: 1,
                        totalAmount: 10000