How to use the benny.suite function in benny

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

github caderek / benny / examples / custom-logging-replace.js View on Github external
const { add, complete, cycle, save, suite } = require('benny')
const path = require('path')

module.exports = suite(
  'Custom logging - console.log',

  add('Add two numbers', () => {
    1 + 1
  }),

  add('Add two numbers', () => {
    1 + 1 + 1
  }),

  add('Add two numbers', () => {
    1 + 1 + 1
  }),

  cycle((result, summary) => {
    // This will be replaced in-place by each cycle:
github caderek / benny / examples / async-madness.js View on Github external
const { add, complete, cycle, save, suite } = require('benny')
const path = require('path')

const delay = (seconds) =>
  new Promise((resolve) => setTimeout(resolve, seconds * 1000))

module.exports = suite(
  'Async madness',

  add('Async benchmark without setup', async () => {
    // You can use await or return - works the same,
    // (async function always returns a Promise)
    await delay(0.5) // Resulting in 2 ops/s
  }),

  add('Async benchmark without setup - many async operations', async () => {
    await delay(0.5)
    await delay(0.5)
    // Resulting in 1 ops/s
  }),

  add('Async benchmark with some setup', async () => {
    await delay(2) // Setup can be async, it will not affect the results
github caderek / benny / examples / composition.js View on Github external
const { add, complete, cycle, save, suite } = require('benny')
const path = require('path')
const { pipe } = require('@arrows/composition')
const A = require('@arrows/array')
const R = require('ramda')
const _ = require('lodash/fp')

// Prepare an array of 1..10
const initialArr = Array.from({ length: 100 }, (_, i) => i + 1)

// Helper functions identical for each case
const isOdd = (x) => x % 2 !== 0
const triple = (x) => x * 3
const sum = (a, b) => a + b

module.exports = suite(
  'Functional array composition',

  add('ramda', () => {
    R.pipe(
      // @ts-ignore
      R.filter(isOdd),
      R.map(triple),
      R.reduce(sum, 0),
    )(initialArr)
  }),

  add('@arrows', () => {
    pipe(
      A.filter(isOdd),
      A.map(triple),
      A.reduce(sum, 0),
github caderek / benny / examples / immutable-transform.js View on Github external
const cloneDeep = require('clone-deep')
const cloneRFDC = require('rfdc')()
const path = require('path')
const _ = require('lodash')

const initializeTestData = () => ({
  foo: {
    bar: {
      baz: 'elo',
      bat: [1, 2, 3],
    },
  },
  batman: 'NaNNaNNaNNaN',
})

module.exports = suite(
  'Immutable transformations',

  add('Pure JS', () => {
    const data = initializeTestData()

    return () => {
      const newData = {
        ...data,
        foo: {
          bar: {
            baz: 'yo',
            bat: data.foo.bar.bat.map((x, i) => (i === 1 ? 7 : x)),
          },
        },
      }
    }
github caderek / benny / examples / allEqual.js View on Github external
add('Declarative', () => {
    allEqualEveryDeclarative(inputHundred)
  }),

  cycle(),
  complete(),
  save({ file: 'all-equal-hundred', folder: path.join(__dirname, 'results') }),
  save({
    file: 'all-equal-hundred',
    folder: path.join(__dirname, 'results'),
    format: 'chart.html',
  }),
)

suite(
  'All equal - million elements',

  add('Imperative', () => {
    allEqualImperative(inputMillion)
  }),

  add('Declarative', () => {
    allEqualEveryDeclarative(inputMillion)
  }),

  cycle(),
  complete(),
  save({ file: 'all-equal-million', folder: path.join(__dirname, 'results') }),
  save({
    file: 'all-equal-million',
    folder: path.join(__dirname, 'results'),
github caderek / arrows / packages / multimethod / benchmark / suites / multimethod-execution.ts View on Github external
import { add, complete, cycle, save, suite } from 'benny'
import { method, multi } from '../../src'
import {
  createNMethodsWithComplexCaseVal,
  createNMethodsWithSimpleFunFun,
  createNMethodsWithSimpleValVal,
} from './helpers'

const { version } = require('../../package.json')

export default suite(
  'Multimethod execution',

  add.skip('Execute identity function for reference', () => {
    const fn = (x) => x

    return () => fn('foo')
  }),

  add('Execute multimethod with default method as value only', () => {
    const fn = multi(method('default'))

    return () => fn('foo')
  }),

  add(
    'Execute multimethod with one simple val/val method - last matching',
github caderek / benny / examples / reduce.js View on Github external
const { add, complete, cycle, save, suite } = require('benny')
const _ = require('lodash/fp')
const R = require('ramda')
const A = require('@arrows/array')
const RB = require('rambda')

const input = Array.from({ length: 100 }, (_, i) => i)

module.exports = suite(
  'Reduce implementations comparison',

  add('lodash/fp', () => {
    _.reduce((a, b) => a + b, 0)(input)
  }),

  add('ramda', () => {
    R.reduce((a, b) => a + b, 0)(input)
  }),

  add('@arrows/array', () => {
    A.reduce((a, b) => a + b, 0)(input)
  }),

  add('@arrows/array first', () => {
    A.reduce.first((a, b) => a + b)(input)
github caderek / benny / examples / allEqual.js View on Github external
if (item !== first) {
      return false
    }
  }
  return true
}

function allEqualEveryDeclarative(arr) {
  const first = arr[0]
  return arr.every((item) => item === first)
}

const inputHundred = [...'a'.repeat(100)]
const inputMillion = [...'a'.repeat(1000000)]

suite(
  'All equal - hundred elements',

  add('Imperative', () => {
    allEqualImperative(inputHundred)
  }),

  add('Declarative', () => {
    allEqualEveryDeclarative(inputHundred)
  }),

  cycle(),
  complete(),
  save({ file: 'all-equal-hundred', folder: path.join(__dirname, 'results') }),
  save({
    file: 'all-equal-hundred',
    folder: path.join(__dirname, 'results'),

benny

A dead simple benchmarking framework

ISC
Latest version published 11 months ago

Package Health Score

61 / 100
Full package analysis

Similar packages