The complexity is $O(nT)$. Look up "automatic differentiation" in Wikipedia.