How to use benny - 10 common examples

To help you get started, we’ve selected a few benny 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 caderek / benny / examples / custom-logging-replace.js View on Github external
}),

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

  cycle((result, summary) => {
    // This will be replaced in-place by each cycle:
    return `Progress: ${
      summary.results.filter((result) => result.completed).length
    } / ${summary.results.length}`
  }),
  complete((summary) => {
    console.log(`Finished ${summary.results.length} benchmarks!`)
  }),
  save({
    file: 'custom-logging-replace',
    folder: path.join(__dirname, 'results'),
  }),
)
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 / custom-logging-replace.js View on Github external
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:
    return `Progress: ${
      summary.results.filter((result) => result.completed).length
    } / ${summary.results.length}`
  }),
  complete((summary) => {
    console.log(`Finished ${summary.results.length} benchmarks!`)
  }),
  save({
    file: 'custom-logging-replace',
    folder: path.join(__dirname, 'results'),
  }),
)
github caderek / benny / examples / custom-logging-replace.js View on Github external
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:
    return `Progress: ${
      summary.results.filter((result) => result.completed).length
    } / ${summary.results.length}`
  }),
  complete((summary) => {
    console.log(`Finished ${summary.results.length} benchmarks!`)
  }),
  save({
    file: 'custom-logging-replace',
    folder: path.join(__dirname, 'results'),
  }),
)
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

    return async () => {
      await delay(0.5) // Still 2 ops/s
github caderek / benny / examples / async-madness.js View on Github external
return async () => {
      await delay(0.5) // Still 2 ops/s
    }
  }),

  add('Sync benchmark with some async setup', async () => {
    await delay(2) // Setup can be async, it will not affect the results

    return () => {
      1 + 1 // High ops, not affected by slow, async setup
    }
  }),

  cycle(),
  complete(),
  save({ file: 'async-madness', folder: path.join(__dirname, 'results') }),
)
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 / async-madness.js View on Github external
return async () => {
      await delay(0.5) // Still 2 ops/s
    }
  }),

  add('Sync benchmark with some async setup', async () => {
    await delay(2) // Setup can be async, it will not affect the results

    return () => {
      1 + 1 // High ops, not affected by slow, async setup
    }
  }),

  cycle(),
  complete(),
  save({ file: 'async-madness', folder: path.join(__dirname, 'results') }),
)
github caderek / benny / examples / async-madness.js View on Github external
await delay(2) // Setup can be async, it will not affect the results

    return async () => {
      await delay(0.5) // Still 2 ops/s
    }
  }),

  add('Sync benchmark with some async setup', async () => {
    await delay(2) // Setup can be async, it will not affect the results

    return () => {
      1 + 1 // High ops, not affected by slow, async setup
    }
  }),

  cycle(),
  complete(),
  save({ file: 'async-madness', folder: path.join(__dirname, 'results') }),
)

benny

A dead simple benchmarking framework

ISC
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis