Skip to main content

estimate execution time before running a function

I have a function that runs for about 0.7 seconds on my not-so-new develop machine. (it runs for about 3 seconds on another machine I tested)

I want to show the user some pre-message about half a second before the above function is done.

I don't want to show the message too long before the function is done as it will be annoying to just look at it and wait...

On the other hand I rather not wait until the function is done because the whole thing starts from a user action and I don't want to "waste" time - it's better if I can show that message while the other function is doing it's job.

I've already added a loop with a short Thread.sleep() to let the pre-message hang if the function was "too fast" but I'm afraid that usually wont be the case...

And so.... I want to see if I could roughly estimate the execution time base on current machine specifications and even by the current CPU usage. and do that before running the function.

Also since we are talking about seconds and milliseconds, if getting this information will take more the a few milliseconds then it's not worth it... in this case I might calculate it only once when the application is loaded.

Anybody has an idea how to do that?

Thanks alot

Ron K
  • 109
  • 1
  • 9