npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

perf-lane

v1.0.7

Published

Performance testing harness for node

Downloads

11

Readme

Build Status

perf-lane

Performance testing harness for Node.js

This library exists to:

  • ease benchmarking with confidence, help write repeatable tests with stable results
  • simplify comparing performance of alternate solutions and for different data sizes
  • simplify testing different setups

Examples

const test = require('perf-lane')
const assert = require('assert')

test.for_n([
  [1, 1],
  [10, 55],
  [30, 832040],
  [40, 102334155]
])

test('fibonacci_1', (p) => {
  function fibonacci_1(n) {
    return n < 1  ? 0
         : n <= 2 ? 1
         : fibonacci_1(n - 1) + fibonacci_1(n - 2)
  }

  let actual = fibonacci_1(p.n)
  assert.equal(actual, p.expected, `fibonacci(${p.n})`)
})

test('fibonacci_2', (p) => {
  const cache = [0, 1, 1]
  function fibonacci_2(n) {
    cache[n] = cache[n] || fibonacci_2(n - 1) + fibonacci_2(n - 2)
    return cache[n]
  }

  let actual = fibonacci_2(p.n)
  assert.equal(actual, p.expected, `fibonacci(${p.n})`)
})
$ perf-lane fibonacci.perf.js
'fibonacci fibonacci_1' for n=1 takes 0-1ms p(95)=0ms tps=6521739 (150000 runs)
'fibonacci fibonacci_1' for n=10 takes 0-1ms p(95)=0ms tps=852273 (150000 runs)
'fibonacci fibonacci_1' for n=30 takes 15-22ms p(95)=15ms tps=65 (978 runs)
'fibonacci fibonacci_1' for n=40 takes 1864-1951ms p(95)=1864ms tps=1 (30 runs)
'fibonacci fibonacci_2' for n=1 takes 0-1ms p(95)=0ms tps=3061224 (150000 runs)
'fibonacci fibonacci_2' for n=10 takes 0-1ms p(95)=0ms tps=688073 (150000 runs)
'fibonacci fibonacci_2' for n=30 takes 0-2ms p(95)=0ms tps=327511 (150000 runs)
'fibonacci fibonacci_2' for n=40 takes 0-1ms p(95)=0ms tps=274725 (150000 runs)

prefetch max

prefetch max

prefetch max

prefetch max

Documentation

test(title: string, fn: (p) => {}) - declare test function with given title.

Test is either sync or returns Promise.

p Attributes:

  • p.n - current n of declared for_n
  • p.expected - current expected of declared for_n
  • p.i - test invokation counter, starts from 0 for each n
  • p.name - test file name
  • p.test - test title
  • p.before(fn) - preparation section, not counted in test time

test.async(title: string, fn: (p) => {}) - declare async test function, that terminates by calling end callback.

p Attributes: see test(title, fn), additionally:

  • p.start - callback to be called on test start (optional)
  • p.end - callback to be called on test end (required)

test.for_n(array) - declare list of [n, expected] pairs for which test will be invoked.

Use it to test performance for different problem sizes, use expected in assertions to make sure tested code is not only fast but also correct.

test.beforeEach(fn) - declare function to be called before each test function invocation

test.afterEach(fn) - declare function to be called after each test function invocation

test.before(fn) - declare function to be called before invoking any tests in a test file

test.after(fn) - declare function to be called after invoking all tests in a test file

test.run() - runs tests, equivalent to running perf-lane from command line.

test.loggers - list of default available loggers

test.options - Available options

  • transactionsPerTest - number of transactions per test, to properly calculate TPS
  • minSecs - minimum time period to repeat single test
  • maxSecs - maximum time period to repeat single test
  • minRuns - minimum numer of single test invocations
  • maxRuns - maximum number of single test invocations
  • logger - logger function
  • report - report generator function
  • format - report charts, svg or png
  • outFile - report log output file
  • envName - environment name, defaults to process.env.HOSTNAME or process.env.TEST_ENV