What Slope does

Slope measures the real time complexity of a JavaScript function instead of asking you to eyeball it. Paste a function, choose a few input sizes, and Slope runs it at each size while counting the primitive operations it actually executes: comparisons, arithmetic, property reads, and calls. It plots those counts on a log-log graph next to the standard Big-O reference curves, so you can read which curve your code really follows. Because it counts operations instead of timing the clock, the same function draws the same graph on any machine, with no JIT warm-up or garbage-collection noise to muddy the result.

How to use it

  1. Paste a single-argument function into the editor, or load a sample: binary search, bubble sort, memoized Fibonacci, and two functions that hide a quadratic.
  2. Pick an input generator that matches what your function expects: a random, sorted, or reverse-sorted array, a string, a nested array, or a plain number for recursive routines.
  3. Add the input sizes to measure at. A wide spread like 100, 1000, 10000 makes the growth curve easier to read.
  4. Press Measure. The points animate in, Slope names the closest-matching curve, and it flags the exact size where a function that started out cheap turns quadratic.

FAQ

Does Slope run my code on a server?
No. Your function runs entirely in your own browser tab. Nothing is uploaded, and there is no backend executing pasted code.
Why count operations instead of timing?
Wall-clock timing depends on the machine, JIT warm-up, and garbage collection, so the same function can look linear on one run and jagged on the next. Counting the operations a function executes is deterministic, so the measured curve reflects the algorithm, not the hardware.
Which functions work best?
Pure, single-argument functions over arrays, strings, or numbers: searches, sorts, and recursive routines. Give recursive numeric functions the "n (number)" generator so they receive a size rather than an array.
Why does a function using .sort() or .includes() look off?
Slope only counts operations inside the code you paste. A built-in like .sort() or .includes() counts as a single call, because its internals are native and not instrumented. Write the loop out explicitly if you want its cost measured.
What does "diverges to O(n²) starting at n=..." mean?
Some functions stay fast until an input crosses a threshold, then fall back to a slower path. Slope compares the curve fitting the early sizes against the full range and flags the size where the growth changes class, which is the moment a "looks O(n)" function is really O(n²).