If you write your code in assembly language you can count clock cycles (been there, done that... for writing my own Serin/serout).
Or you can setup and use one of the other system clocks, such as TimerZ0/1(16 bit), TimerV(8 bit) or TimerB1(8 bit). These will be in some multiple of clock cycles (20mhz on Bap40 I believe). Depending on the length of time you need and resolution and which clock you use, you will probably need to setup an overflow interrupt and handler. Not hard, I have several examples up on the forum, including the thread: viewtopic.php?f=4&t=3496