Compiler pre-concatenation of const string values.

  • Thread starter Thread starter Colin Green
  • Start date Start date
C

Colin Green

I have just noticed an odd difference in performance between two
almost identical routines in a lexical analyser I was writing.

On investigation I found that the slower routine was repeatedly
concatenating two const string values together. On declaring the
concatenated result as a seperate variable the slow routine's
performance increased to match that of the faster one.

I had written this code fully expecting that the two const strings
would be concatenated by the optimizer since it seems like a trivial
way of making dramatic performance gains, and yet this optimization
isn't being done.

I am using Framework 1.1 / Visual Studio 2003 and I am testing a
release build with optimisation switched on.

Am I missing something or is this correct behaviour by the
compilers/optimisers?!

Colin.
 
Back
Top