Calculating time for each algorithm