benny-vipu

run benny benchmarks in the browser headless using vipu

Usage no npm install needed!

<script type="module">
  import bennyVipu from 'https://cdn.skypack.dev/benny-vipu';
</script>

README

benny-vipu

run benny benchmarks in the browser headless using vipu

🔧 Install · 🧩 Example · 📜 API docs · 🔥 Releases · 💪🏼 Contribute · 🖐️ Help


Install

$ npm i benny-vipu -g

CLI

Usage: benny-vipu [options] <file>

                     <file>  Benchmark filename to run

   -c, --clear               Clear screen between page reloads
   -f, --force               Force cache renewal
   -d, --debug               Print debug information
   -p, --precision=n         Results decimal precision digits (default: 2)
   -s, --sort                Sort results by winners (default: false)
   -w, --width=n             Ascii chart width (default: 30)
       --min=n               Minimum iteration samples (default: 3)
       --max=n               Maximum time in seconds (default: 1)

Example

import { suite, add, finish } from 'benny-vipu'

const container = document.body

const clear = () => (container.innerHTML = '')

const bench = async () => {
  for (const count of [100, 1_000, 10_000]) {
    await suite(
      `insert ${count} elements`,

      add('createElement/appendChild', () => {
        clear()
        for (let i = 0; i < count; i++) {
          const div = document.createElement('div')
          container.appendChild(div)
        }
      }),

      add('html+=div + innerHTML', () => {
        clear()
        let html = ''
        for (let i = 0; i < count; i++) {
          html += '<div></div>'
        }
        container.innerHTML = html
      }),

      add('Array.fill.join() + innerHTML', () => {
        clear()
        container.innerHTML = Array(count).fill('<div></div>').join('')
      }),
    )
  }
}

bench().then(finish)

API

Table of Contents

run

src/index.ts:58-105

Runs a given benchmark file.

Parameters

  • filename string The benchmark filename

  • options Options (optional, default new Options())

    • options.clear Clear screen between page reloads
    • options.force Force cache renewal
    • options.debug Print debug information
    • options.precision Results decimal precision digits (default: 2)
    • options.sort Sort results by winners (default: false)
    • options.width Ascii chart width (default: 30)
    • options.minSamples Minimum iteration samples (default: 3)
    • options.maxTime Maximum time in seconds (default: 1)

Contribute

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2021 stagas