Free beta: 60 days of full access, no card needed.173 seats leftSign up free

We use necessary cookies to run the site (sign-in and language). If you accept, we also load Google Analytics to see which pages are used, and Google reCAPTCHA to keep spam off the contact and bug-report forms. Privacy policy

FREE TOOL

Big O calculator

Paste a JavaScript or TypeScript function. It runs in your browser at growing input sizes, and the timings tell you which complexity class it follows. Nothing is sent to a server.

Takes up to ten seconds. The function is called with one argument.

How the calculator works

The calculator calls your function with inputs of size 32, 64, 128 and so on, doubling each time, and times every size.

Fast calls are timed in batches, because a browser's clock only ticks every tenth of a millisecond. Each call gets a fresh input, so a function that sorts in place cannot speed up its own next call.

Then it fits every common class to the timings and picks the one that explains them best. When two classes fit almost equally, it says so.

Common time complexities, fastest first

A rough guide: a modern machine does about a hundred million simple steps a second. The last column is the largest input that fits in one second.

ClassTypical coden in one second
O(1)Read one element, look up a hash mapany size
O(log n)Binary search, a balanced tree lookupany size
O(n)One loop over the input, two pointers10⁸
O(n log n)Sorting, a heap of n items5·10⁶
O(n²)Two nested loops over the input10⁴
O(n³)Three nested loops, Floyd-Warshall450
O(2ⁿ)Every subset, naive recursion26

What a measurement cannot tell you

The calculator measures one kind of input. Quicksort is O(n log n) on random data and O(n²) on some sorted inputs, so try the input type your problem actually gets.

O(n) and O(n log n) are hard to tell apart over a short range, because log n grows so slowly. The result says when it is unsure.

The calculator measures time, not memory. In an interview you still have to explain why, and that is the part worth practising.

From measuring to knowing

Every pattern page names its complexity and says why. Start with the one your problem looks like. All patterns on one page