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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@neabyte/perf-observer

v0.1.0

Published

A lightweight performance observer using native Node.js performance APIs for debugging and benchmarking

Readme

Perf Observer License: MIT

A lightweight performance observer using native Node.js performance APIs for debugging and benchmarking.

Table of Contents

Installation

npm install @neabyte/perf-observer

Quick Start

import perf from '@neabyte/perf-observer'

// Track a function automatically
const trackedFunction = perf.track(() => {
  // Your code here
  return 'result'
})

// Manual timing
perf.start('my-process')
// ... do work ...
const duration = perf.end('my-process')

// Run benchmarks
const result = perf.benchmark(() => {
  // Function to benchmark
}, { iterations: 1000 })

API Reference

Core Methods

| Method | Description | Returns | |--------|-------------|---------| | start(name) | Start timing a process | void | | end(name) | End timing and get duration | number (ms) | | track(fn, name?) | Wrap function with automatic timing | Function | | getStats(name?) | Get performance statistics | ProcessStats | | findSlowProcesses(threshold?) | Find processes exceeding threshold | ProcessEntry[] | | benchmark(fn, options?) | Run benchmark test | BenchmarkResult |

Types

ProcessStats

| Property | Type | Description | |----------|------|-------------| | count | number | Number of processes | | avgDuration | number | Average duration (ms) | | minDuration | number | Minimum duration (ms) | | maxDuration | number | Maximum duration (ms) | | p95Duration | number | 95th percentile (ms) | | p99Duration | number | 99th percentile (ms) |

BenchmarkOptions

| Property | Type | Default | Description | |----------|------|---------|-------------| | iterations | number | 1000 | Number of test iterations | | warmup | number | min(100, iterations/10) | Warmup iterations | | maxDuration | number | 60000 | Max test duration (ms) | | outlierThreshold | number | 3 | Outlier detection threshold | | trackMemory | boolean | false | Track memory usage | | name | string | fn.name | Custom benchmark name |

BenchmarkResult

| Property | Type | Description | |----------|------|-------------| | name | string | Benchmark name | | iterations | number | Actual iterations completed | | warmupIterations | number | Warmup iterations performed | | totalTime | number | Total time (ms) | | avgTime | number | Average time per iteration (ms) | | minTime | number | Minimum iteration time (ms) | | maxTime | number | Maximum iteration time (ms) | | p95Time | number | 95th percentile time (ms) | | p99Time | number | 99th percentile time (ms) | | stdDev | number | Standard deviation | | outliers | number | Number of outliers removed | | memoryDelta | number? | Memory usage change (bytes) |

Usage Examples

Basic Timing

// Manual timing
perf.start('database-query')

// Simulate database operation
await new Promise(resolve => setTimeout(resolve, 50))
const duration = perf.end('database-query')
console.log(`Query took ${duration}ms`)

Function Tracking

// Automatic timing
const expensiveOperation = perf.track(async () => {
  await new Promise(resolve => setTimeout(resolve, 100))
  return 'completed'
})

const result = await expensiveOperation()

Duplicate Name Behavior: Multiple functions with the same name will overwrite each other's performance data. Only the last function's data will be preserved in statistics. To avoid data loss:

  • Use unique names: perf.track(fn, 'unique-name')
  • Add hash suffixes: perf.track(fn, 'operation-' + crypto.randomBytes(4).toString('hex'))
  • Use function names: function myOperation() {} then perf.track(myOperation)

Anonymous functions all use 'anonymous' name and will overwrite each other.

Performance Statistics

// Get stats for all processes
const allStats = perf.getStats()
console.log(`Average: ${allStats.avgDuration}ms`)

// Get stats for specific process
const queryStats = perf.getStats('database-query')
console.log(`95th percentile: ${queryStats.p95Duration}ms`)

Benchmarking

// Simple benchmark
const result = perf.benchmark(() => {
  return Math.random() * 1000
}, 10000)

console.log(`Average: ${result.avgTime}ms`)
console.log(`Standard deviation: ${result.stdDev}ms`)

// Advanced benchmark with options
const advancedResult = perf.benchmark(
  () => {
    // Simulate data processing
    return Array.from({ length: 1000 }, (_, i) => i * 2)
  },
  {
    iterations: 5000,
    warmup: 100,
    trackMemory: true,
    outlierThreshold: 2,
    name: 'data-processing'
  }
)

Finding Slow Processes

// Find processes taking longer than 1 second
const slowProcesses = perf.findSlowProcesses(1000)
slowProcesses.forEach(process => {
  console.log(`${process.name}: ${process.duration}ms`)
})

Requirements

  • Node.js >= 22.0.0
  • TypeScript (optional, for type definitions)

Contributing

Issues and pull requests are welcome on GitHub.

License

This project is licensed under the MIT license. See the LICENSE file for more info.