c++ccompilationcompiler-optimization

Performance difference between "int a, b;" and "int a; int b;"?


It's an easily described in question as the title says.

This question came to my mind every time I can put two separate statements together in a block. Especially when I code for CPU cost problems like NP-complete problems.

Is there any, necessary to combine two separate statements together?.


Solution

  • Performance difference between “int a, b;” and “int a; int b;”?

    Those declarations are semantically equivalent, and there is no reason why either would generate different program from the other, and therefore no reason why there would be difference in performance.

    However, the first declaration is shorter by a few characters, so the compilation process might be a few micro-seconds faster for the time that's needed to load the source file from the disk.

    Is there any necessary to combine two separate statements together?

    In general, no.