-2

I have small c program that I wrote on c use with lot of cpu and compile it with visual studio 17,running on windows.

I want to speed up this exe file without changing the code, only with changing the compilation method.

I don't care about security code ,only speed, I know the OS and processor thatvthis progran will run on it (if it help).

So how can I faster my prigram with changing the compiler/ disable some security flag/ compile it to spesific os/ processor?

sepp2k
  • 363,768
  • 54
  • 674
  • 675

2 Answers2

0

If the compiler doesn't do optimizations by default, you can add some arguments to get the maximum speed from the compiler. You can find all kind of these arguments here. In your case probably it is /O2.

To set this compiler option in the Visual Studio development environment:

  1. Open the project's Property Pages dialog box.

  2. Click the C/C++ folder.

  3. Click the Optimization property page.

  4. Modify the Optimization property.

Amir
  • 996
  • 7
  • 17
  • What is the diffrence between `02` and `0x` what is the maximum optimization? And how I set it in visual studio? – Jonert6544 Aug 12 '18 at 06:44
  • o2 only optimizes for the speed, but ox optimizes for both speed and compiled binary file size. – Amir Aug 12 '18 at 17:10
  • So if I dont care about file size and I only want speed do I need to put 02? What is the default option when compile pn release? – Jonert6544 Aug 12 '18 at 18:49
  • Yes, you should put O2 for speed. And the default option is [/Ot](https://msdn.microsoft.com/en-us/library/f9534wye.aspx) is the. – Amir Aug 12 '18 at 22:22
  • `ot` is fast code and `02` is very fast code? Is there say about in avarege how much (in %) the speed is between those option? By the way I saw `For example, the Optimization property, by default, is set to Maximize Speed (/O2) in a Release configuration` here https://msdn.microsoft.com/en-us/library/669zx6zc.aspx – Jonert6544 Aug 13 '18 at 03:53
  • /o2 enables /ot and other options as well, you can see the difference here https://stackoverflow.com/questions/6007378/visual-c-compiler-optimization-flags-difference-between-o2-and-ot – Amir Aug 13 '18 at 07:04
0

In Project -> Properties set the optimization flags to suit you: enter image description here

0___________
  • 60,014
  • 4
  • 34
  • 74
  • Mark all choise there as yes? Or only the first? What are the effect of those changes? Why they are disable by default – Jonert6544 Aug 12 '18 at 04:58
  • You are showing the debug settings, where optimisation is switched off. Don't the release settings (which the OP is using) have optimisation enabled by default? – alk Aug 12 '18 at 07:59