Optimal way of making timed code

I generally use interrupts.