added timing functionality to alg1 and alg2