healeycodes / nodots-lang

𝐧𝐝 A small programming language with an interpreter, and a WebAssembly compiler.
https://healeycodes.com/profiling-and-optimizing-an-interpreter
12 stars 1 forks source link

Add line profiler #5

Closed healeycodes closed 5 months ago

healeycodes commented 5 months ago

Add a new option to the CLI that provides a line profiler (kinda inspired by cProfile).

For now, just profile the calls.

Example:

$ python cli.py --profile fib.nd
                                      ncalls  tottime  percall
for (i = 0; i < 21; i = i + 1)
  # recursive (slow)
  fun fib(x)
    if (x == 0 or x == 1)
        return x;
    fi
    return fib(x - 1) + fib(x - 2);  x57270   11.2s    195µs
  nuf
  log(fib(i));                       x42      1.9s     46ms
rof