Optimize loop times for digest function.