Home / Science / Maths, statistics and computing / Computer science / Big-O and runtime comparison plotterTool #574

Big-O plotter: compare O(1), O(log n), O(n), O(n log n), O(n²), O(2ⁿ), O(n!) and fit your timings to a complexity class

Draw how each complexity class grows, add your own formulas in n, and see how long each takes at any input size. Paste measured run times (or open a file, or time built-in algorithms in your browser) and a least-squares fit picks the best Big-O class.

Keep it one tap away for everyday use.

Bookmark Big-O and runtime comparison plotter?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Curves
  2. Timings
  3. Best fit
Nothing is uploadedWorks offline once open

Growth curves

How long at one size

A modern computer does very roughly one simple step per nanosecond. Steps here are the growth function itself, without the constant a real program adds.

Fit your timings

Each class is fitted as time = a + b × g(n) by least squares. The best is the smallest leftover (residual) sum of squares. Close classes such as n and n log n need a wide range of n to tell apart.

Time an algorithm in this browser

Each size is run again and again for at least 40 ms, three times, and the middle result is kept. The results go into the fit box above. Timings vary with the browser, the device and what else is running; the copy of the list each sort makes is included.

Save

Download

What it does

Big-O notation says how the work an algorithm does grows as its input grows. The difference between classes is easy to state and hard to feel: at n = 1,000, an O(n²) method takes a million steps, while an O(2ⁿ) one would take longer than the age of the universe many times over. This tool makes that visible and lets you test your own code against it.

  • Growth curves: O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ) and O(n!) on one chart, plus up to four formulas of your own in n (such as n(n − 1)/2 or 3n² + 10n).
  • How long at one size: the number of steps for each class at any n, written out even when it is astronomically large, and the time it would take at a chosen speed per step.
  • Fit your timings: paste input sizes and measured times (or open a CSV or Excel file). Each class is fitted by least squares and the best one is picked.
  • Time an algorithm in this browser: run one of eight small built-in algorithms (a loop, binary search, the built-in sort, merge sort, insertion sort, a pair loop, matrix multiplication, every subset) at several sizes, and the timings go straight into the fit.

How to use it

  1. Tick the classes to draw and, if you like, type formulas using n. Set how far n goes. The log scale (on by default) lets very different curves share one chart; untick it to see how quickly the steep ones take off, and use Cut the y axis at to stop them filling the chart.
  2. Under How long at one size, type an n and the time one step takes. The default, 1 ns, is very roughly one simple operation on a modern computer.
  3. In Fit your timings, paste two columns: n and the time it took. Any time unit works; a header such as “time (ms)” labels the chart.
  4. Or choose an algorithm under Time an algorithm in this browser and press Run timings.
  5. Save the fit table or the size table as CSV, or everything as an image, PDF or Word file.

How the fit works

For each class with growth function g(n), the tool finds the a and b that make time = a + b × g(n) closest to your points by least squares. The constant a soaks up fixed start-up costs. The fit with the smallest residual sum of squares (the leftover after the fit) wins, as long as b is positive: a time that falls as n grows is not that class. Classes whose g(n) is astronomically large at your n (2ⁿ and n! for n above about 500 and 100) are left out. The log-log slope is a second, class-free check: the slope of log time against log n is about 1 for O(n), 2 for O(n²) and 3 for O(n³), and a little above 1 for O(n log n).

Worked example

The example timings are made up: n = 1,000, 2,000, 4,000, 8,000 and 16,000 took 0.8, 1.7, 3.1, 6.9 and 13.2 ms. The page shows Best fit: O(n) with time = −0.01250 + 8.310e-4 × n and R² = 0.9988. The next best, O(n log n), leaves a residual 2.38 times larger, and the log-log slope is 1.01. O(n²) fits clearly worse (R² 0.941).

In the size table at n = 1,000 with 1 ns per step: O(n) is 1,000 steps (1 µs), O(n²) is 1,000,000 steps (1 ms), O(n³) is 1,000,000,000 steps (1 s), O(2ⁿ) is 1.07 × 10^301 steps (3.40 × 10^284 years) and O(n!) is 4.02 × 10^2,567 steps.

Tips

  • Use sizes that double each time, over at least a factor of 10. O(n) and O(n log n) differ by only a slowly growing factor, so a narrow range cannot tell them apart.
  • Time each size several times and use the middle value; one slow run can pull a fit off.
  • Small n is dominated by fixed costs. The constant a in the fit absorbs some of that, but start from sizes where a run takes at least a millisecond.
  • Browser timers are rounded for security, so the timing section repeats each run for at least 40 ms.

What it does not do

It fits one class at a time, so it cannot tell you that a program is “n² for small n, then n log n”. It does not analyse source code. Times measured in a browser depend on the JavaScript engine, the device and what else is running, so treat them as a demonstration, not a benchmark.

FAQ

Why does the best fit change when I add one more point? When two classes fit almost equally well (look at “Next best”), small noise decides between them. More sizes over a wider range settle it.

Is my data sent anywhere? No. The fit and the timings run in your browser and the page keeps working offline once it has loaded.

Where the numbers come from

  • Complexity classes and their growth functions are standard computer science; n! is computed from the log-gamma function so very large n never overflows.
  • Checked against numpy: for 8 timing sets (synthetic data of every class with noise, plus one hand-made set), every class's a, b, residual sum of squares and R² match np.linalg.lstsq, the best class matches, and the log-log slope matches np.polyfit. 1000! = 4.02 × 10^2567 checked with scipy.special.gammaln.
  • The example timings are made up for this tool.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Trend and anomaly analyser #138 Paste or open a time series (yearly, monthly or any steps) and test for a trend with Mann-Kendall, the Hamed-Rao autocorrelation correction or the seasonal test, get Sen's slope with its confidence interval, a Pettitt change point and anomalies from a baseline period. Publication plot maker #27 Paste columns or open a CSV or Excel file and get a clean scientific figure with error bars, sized for a journal column. Download vector SVG or PDF, or PNG at 300 or 600 dpi. Your data stays in your browser. Algorithm visualiser #573 Watch bubble, insertion, selection, merge, quick, heap, counting and radix sort work on your own list, one step at a time, with exact comparison, swap and write counts. Also linear and binary search, and the tables for longest common subsequence, edit distance and the 0/1 knapsack. Floating point inspector (IEEE 754) #575 See how a computer really stores 0.1 or any other number: the sign, exponent and mantissa bits in half, single and double precision, the exact stored value to the last digit, the rounding error, the next float up and down, and the ULP. Flip bits to see what any pattern means. Cache and memory hierarchy simulator #576 Run an address trace (pasted, from a file, or generated: array walks, matrix multiply loop orders, random) through one or two cache levels. See every hit and miss with its tag, set and offset, compulsory, capacity and conflict misses, the cache contents at any step, and the average memory access time. Finite state machine and regex visualiser #559 Turn a regular expression into a Thompson NFA, a DFA (subset construction) and the minimal DFA, drawn as state diagrams with transition tables. Step through a test string state by state, or type your own DFA and minimise it.