calculate the running time of algorithm