Does moving variable declaration outside of a loop actually increase performance?
问题 I'm writing very processor-intensive cryptography code (C#), so I'm looking for any performance gains, no matter how small. I've heard opinions both ways on this subject. Is there any performance benefit at all to int smallPrime, spGen; for (int i = 0; i < numSmallPrimes; i++) { smallPrime = smallPrimes[i]; spGen = spHexGen[i]; [...] } over this? for (int i = 0; i < numSmallPrimes; i++) { int smallPrime = smallPrimes[i]; int spGen = spHexGen[i]; [...] } Does the compiler do this already? 回答1: