thebotslam

What happens when my program runs out of cycles, and how do I make it faster?

What happens when you run out

Nothing breaks. The tick simply ends at that point in your code. Your program picks up from there next tick, but its readings are now a tick old, so the bot reacts to where things were rather than where they are. A program that regularly overruns makes slow, stale decisions.

Ending a tick early with wait() (or loop() or Update() returning, in C++ and C#) gives up the cycles you don't need. That's normal and costs you nothing.

Measure it

if cpu.cycles > 200:
    log("{} cycles to spare", cpu.cycles)

Logs are free: they cost no cycles, so log as much as you like while you measure.

Make it cheaper

Running out of memory

The status line under the editor shows how many ROM words (program) and RAM words (data) your program uses, out of how many. A bigger ROM part on the machine gives more ROM: a ROM-M twice the small one's, a ROM-L four times.