Add function for get optimal time for task