且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

生成最快的可执行文件

更新时间:2023-09-30 11:49:46

1)使用 __ restrict



2)通过使用 __ pure



3)可以找到SSE / SIMD的简介此处此处。互联网并没有完全溢出与这个话题的文章,但足够了。对于宏并行化,您可以尝试使用 OpenMP 。这是一个易于任务并行化的编译器标准 - 实质上,你告诉编译器使用一些#pragmas代码的某些部分是可重入的,编译器为你自动创建线程。



5)我第二个interjay的观点,PGO可以很好地帮助。与#3和#4不同,它几乎可以轻松添加。


I have a very large program which I have been compiling under visual studio (v6 then migrated to 2008). I need the executable to run as fast as possible. The program spends most of its time processing integers of various sizes and does very little IO.

Obviously I will select maximum optimization, but it seems that there are a variety of things that can be done which don't come under the heading of optimization which do still affect the speed of the executable. For example selecting the __fastcall calling convention or setting structure member alignment to a large number.

So my question is: Are there other compiler/linker options I should be using to make the program faster which are not controlled from the "optimization" page of the "properties" dialog.

EDIT: I already make extensive use of profilers.

1) Reduce aliasing by using __restrict.

2) Help the compiler in common subexpression elimination / dead code elimination by using __pure.

3) An introduction to SSE/SIMD can be found here and here. The internet isn't exactly overflowing with articles about the topic, but there's enough. For a reference list of intrinsics, you can search MSDN for 'compiler intrinsics'.

4) For 'macro parallelization', you can try OpenMP. It's a compiler standard for easy task parallelization -- essentially, you tell the compiler using a handful of #pragmas that certain sections of the code are reentrant, and the compiler creates the threads for you automagically.

5) I second interjay's point that PGO can be pretty helpful. And unlike #3 and #4, it's almost effortless to add in.