Let $p$ be amount invested over $N$ years. $r$ = rate of return. $t$ = tax rate.
You pay taxes upfront. That reduces $p$ to $(1-t)p$. After $N$ years this becomes $(1+r)^N(1-t)p$ which you can withdraw tax free.
You don’t pay any taxes on $p$. After $N$ years the amount becomes $(1+r)^Np$. Now when you withdraw it, you pay tax and so the net amount becomes $(1+r)^Np(1-t)$ which is same as earlier.
Of course, the catch is the assumption that $t$ remains same in both cases.