There is probably a better way to do this, but this might work:
use rtc clock to grab the time before and after your function call and subtract the results.
the output of the clock is a 48 bit counter that runs at 128KHz.
// rtc clock rate is 128KHz so divide by 128 if you want milliseconds.
raw_clock.rtc64 = raw_clock.rtc64 >> 7;