Complexity Lens

Paste a JavaScript function. It runs on bigger and bigger inputs, and you watch its Big-O growth rate get measured as it goes.

Growth rate
–
Candidates · average fit error
    Measurements table
    nmeasuredbest fit

    How it works

    1. Run it at growing sizes. Your function runs in a Web Worker (a background thread) at n = 16, 32, 64, … until one call takes over a second. Fast calls are timed in batches because browser clocks only tick every ~0.1 ms.
    2. Fit each candidate. For every growth rate f(n) (1, log n, n, n log n, n², n³, bⁿ) it finds the best time ≈ a·f(n) + b. Here a is the cost of one step and b is fixed overhead.
    3. Pick the best fit. The candidate with the smallest relative error wins. If a simpler one fits almost as well, the simpler one wins.

    These are real timings, so they're noisy. Garbage collection, CPU caches and the JavaScript JIT all shift the numbers, and O(n) vs O(n log n) is hard to tell apart. Treat the result as evidence, not proof. The proof is still reasoning about the code.