create a script to find the optimal time