Use long instead of int to mesure time
Reset the timer only when a task was successful

Currently the timer is reset after each iteration (thus repeats the
minimum wait every time).
Merge branch 'master' into search-1.5.x