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

mavu

v0.2.4

Published

A CLI tool that estimates Big-O time complexity of JavaScript code using AST analysis.

Readme

mavu

A CLI tool that estimates Big-O time complexity of JavaScript code using static AST analysis.

npm bundle size npm license

Features

  • Whole-file analysis: Finds loops (including nested), array-method iterations (.map(), .forEach(), etc.), and recursion to estimate O(1), O(n), O(nᵏ), O(log n) or O(2ⁿ).
  • Per-function breakdown: Get a table of each function’s complexity.
  • Explain mode: Shows a little ASCII tree of how your code’s complexity was derived.
  • Batch & glob support: Run against single files, directories or globs (src/**/*.js).
  • Multiple output formats: JSON, plain summary, ASCII table, or full explanation.

Installation

npm install -g mavu

Or add it to your project:

npm install --save-dev mavu

Usage

mavu [options] <file|glob>...

Examples

Simple summary

mavu src/samples/fibRecursive.js
# src/samples/fibRecursive.js: O(2^n)

Plain summary

mavu src/samples/logLoop.js --summary
# File: src/samples/logLoop.js
# Complexity: O(log n)

JSON output

mavu src/samples/noLoops.js --json
{
  "file": "src/samples/noLoops.js",
  "complexity": "O(1)",
  "reason": ["No recursion/log detected; based on loop nesting.", "Max loop nesting depth: 0"]
}

ASCII table

mavu src/samples/*.js --table
┌──────────────────────────┬────────────┐
│ File                     │ Complexity │
├──────────────────────────┼────────────┤
│ noLoops.js               │ O(1)       │
│ logLoop.js               │ O(log n)   │
│ fibRecursive.js          │ O(2^n)     │
└──────────────────────────┴────────────┘

Per-function breakdown

mavu src/samples/multiFunc.js --per-function
Functions in src/samples/multiFunc.js
┌──────────┬────────────┐
│ Function │ Complexity │
├──────────┼────────────┤
│ foo      │ O(n)       │
│ bar      │ O(n^2)     │
│ baz      │ O(n)       │
└──────────┴────────────┘

Explain & ASCII tree

mavu src/samples/logLoop.js --explain
src/samples/logLoop.js → O(log n)
↳ Detected logarithmic loop (i *= 2)
└─ Max loop nesting depth: 1

Detected logarithmic loop (i *= 2)
Max loop nesting depth: 1

CLI Options

| Flag | Description | | -------------------- | --------------------------------------- | | -J, --json | Emit JSON (object or array) | | -S, --summary | Plain summary (File: / Complexity:) | | -T, --table | ASCII table of files & complexities | | -P, --per-function | Table of each function’s complexity | | -E, --explain | Full reasoning + ASCII tree | | -v, --version | Show version | | -h, --help | Show this help message |

How It Works

  1. Parsing Uses Acorn to parse your code to an AST.

  2. Loop Analysis Walks ForStatement / WhileStatement / array-method calls to compute nesting depth and detect logarithmic strides.

  3. Recursion Analysis Builds a simple call graph to find self-calls, linear vs. tree vs. mutual recursion.

  4. Decision Applies:

    • Exponential if tree recursion or mutual recursion seen
    • O(nᵈ) for maximum loop nesting depth d
    • O(log n) if any loop doubles (or halves) its index
    • O(n) if linear recursion or depth=1
    • O(1) otherwise

License

MIT © hipuku