Helper to time a function.