Pathwise optimization for optimal stopping problems