Bölüm 1.1 · Simülatör

Algorithm Complexity Analysis

← Bölüm 1.1

Complexity

Input Sizes

Press Start to time the function.

The measured average running time for each input size will be plotted here.

Algorithm Complexity Analysis

Edit or select a JavaScript function, run it at several input sizes, and compare the measured execution times.

How to use

  • Choose a complexity class (O(log n), O(n), O(n log n), O(n²), O(n³)). The editor is filled with a sample function myFunction(size) of that class and the five input sizes are set to a suitable preset (each size doubles, except for O(log n)).
  • You may edit the function or the sizes. The code must define a function named myFunction that takes the input size as its only argument.
  • Press Start. After one discarded warm-up measurement, for each input size the function is run a few times to warm up and then repeated for about 40 ms; the chart shows the average time per call in milliseconds (or microseconds when all times are below 1 ms).

Reading the chart

  • For O(n) doubling n should roughly double the time; for O(n²) it should roughly quadruple it, and for O(n³) multiply it by about eight.
  • For O(log n) the curve flattens quickly: going from 10 to 100,000 adds only a few loop iterations.
  • Real measurements are noisy: the JIT compiler, caches, garbage collection and other browser activity all affect the time. Run the analysis more than once and look at the trend, not single points.

Note

The selected code is executed locally in your browser. Very large inputs or expensive functions may temporarily make the page less responsive.