Skip to main content
added 115 characters in body
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k

Possibly the try/catch block forces more registers to be saved and restored, so the JIT uses those for the loop as well... that'swhich happens to improve the best I can come up with atperformance overall. It's not clear whether it's a reasonable decision for the momentJIT to not use as many registers in the "normal" code.

Possibly the try/catch block forces more registers to be saved and restored, so the JIT uses those for the loop as well... that's the best I can come up with at the moment.

Possibly the try/catch block forces more registers to be saved and restored, so the JIT uses those for the loop as well... which happens to improve the performance overall. It's not clear whether it's a reasonable decision for the JIT to not use as many registers in the "normal" code.

added 226 characters in body
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k

EDIT: Just tried this on my x64 machine. The x64 CLR is much faster (about 3-4 times faster) than the x86 CLR on this code, and under x64 the try/catch block doesn't make a noticeable difference.

EDIT: Just tried this on my x64 machine. The x64 CLR is much faster (about 3-4 times faster) than the x86 CLR on this code, and under x64 the try/catch block doesn't make a noticeable difference.

added 226 characters in body
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k

I'm still trying to work out exactly what it all means (x86 isn't my strong suit EDIT:) but Okay, I've now looked through the code and I thought I'd putthink I can see how each version works... and I believe the slower version is slower because it up here for others to look atuses fewer registers and more stack space. Of course underFor small values of .NET 4n that's possibly faster (or x64) it would all be different,- but hopefully this will give uswhen the loop takes up the bulk of the time, it's slower.

Possibly the try/catch block someforces informationmore registers to be saved and restored, so the JIT uses those for the loop as well... that's the best I can come up with at the moment.

I'm still trying to work out exactly what it all means (x86 isn't my strong suit :) but I thought I'd put it up here for others to look at. Of course under .NET 4 (or x64) it would all be different, but hopefully this will give us some information...

EDIT: Okay, I've now looked through the code and I think I can see how each version works... and I believe the slower version is slower because it uses fewer registers and more stack space. For small values of n that's possibly faster - but when the loop takes up the bulk of the time, it's slower.

Possibly the try/catch block forces more registers to be saved and restored, so the JIT uses those for the loop as well... that's the best I can come up with at the moment.

added 3988 characters in body
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k
Loading
added 550 characters in body
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k
Loading
added 313 characters in body
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k
Loading
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k
Loading