Big-O Estimator from Timings

Time your code on a few input sizes, paste the numbers, and see which growth rate fits best.

How it works

Time your code at several input sizes and paste size and time pairs. For each growth rate (n, n log n, n squared and so on) the tool divides every time by that rate. If the growth rate is right, all the results are about the same constant. The one with the smallest spread wins.

The formula

for a model f(n): ratio = time / f(n)
misfit = spread of log(ratio)
log-log slope of time against n: 1 is linear, 2 is quadratic

Worked example

Times 0.8, 3.1, 12.6 and 50 for n = 1000, 2000, 4000 and 8000: each doubling multiplies the time by about 4, so it fits O(n^2).

Good to know

Common questions

Can this prove a complexity?
No. It only fits measured data. A proof comes from analysing the code.
Why does n log n look like n?
Over a small range log n changes slowly. Use a wide range of sizes.
Does the unit of time matter?
No. Seconds, milliseconds and ticks all work.

More in CS Labs & Coding.