Monitors running time with a given function