使用-O选项进行编译可以提供不同的运行时间! [英] Compiling with -O option gives different running time!
问题描述
当我编译程序添加-O选项时,我的
程序的运行时间要小得多。例如,如果我像这样编译我的程序
g ++ -Wall -g prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list .cc loadavltree.cc -o p2 -lm
它的运行时间大约是12秒。
但如果我用
g ++ -Wall -g -O prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 - lm
它的运行时间大约是7秒。
我是C ++的新手,所以不能弄清楚为什么它会如此不同。 br />
有什么想法吗?
谢谢,
Aamir
Hi,
When I compile my program adding -O option, the running time of my
program is much smaller. For example if i compile my program like this
g++ -Wall -g prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
its run time is around 12 seconds.
but if i compile it with
g++ -Wall -g -O prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
its run time is around 7 seconds.
I am really new at C++ so can''t figure it out why is it so different.
Any idea?
Thanks,
Aamir
推荐答案
aamirche ... @ gmail.com写道:
aamirche...@gmail.com wrote:
当我编译我的程序时添加-O选项,我的
程序的运行时间要小得多。例如,如果我像这样编译我的程序
Hi,
When I compile my program adding -O option, the running time of my
program is much smaller. For example if i compile my program like this
< snip>
运行
man gcc
然后搜索-O
Tom
<snip>
run
man gcc
And then search for "-O"
Tom
aa*********@gmail.com 写道:
aa*********@gmail.com wrote:
当我编译我的程序添加-O选项时,我的
程序的运行时间要小得多。例如,如果我像这样编译我的程序
g ++ -Wall -g prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
Urm ...这是非主题两次(C ++,特定于实现)。
其运行时间约为12秒。
但如果我用它编译它
g ++ -Wall -g -O prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
When I compile my program adding -O option, the running time of my
program is much smaller. For example if i compile my program like this
g++ -Wall -g prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
Urm ... this is off-topic twice (C++, and implementation-specific).
its run time is around 12 seconds.
but if i compile it with
g++ -Wall -g -O prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
如果您不知道-O是什么,为什么要将它添加到命令行?
-
Chris"如果你这样做了,你为什么要问? Dollin
我们没时间找到我们想知道的一切。 /镲片的冲突/
If you don''t know what -O is for, why did you add it to the command line?
--
Chris "and if you did, why are you asking?" Dollin
"We did not have time to find out everything we wanted to know." /A Clash of Cymbals/
aa ********* @ gmail.com 写道:
当我编译程序时添加-O选项,我的
程序的运行时间要小得多。例如,如果我像这样编译我的程序
g ++ -Wall -g prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
它的运行时间大约是12秒。
但如果我用它编译它
g ++ -Wall -g -O prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
它的运行时间大约是7秒。
我真的C ++的新功能所以无法弄清楚为什么它如此不同。
任何想法?
Hi,
When I compile my program adding -O option, the running time of my
program is much smaller. For example if i compile my program like this
g++ -Wall -g prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
its run time is around 12 seconds.
but if i compile it with
g++ -Wall -g -O prog2.cc avltree.cc cells_list.cc hashsep_query.cc
hashsep_point.cc int_list.cc loadavltree.cc -o p2 -lm
its run time is around 7 seconds.
I am really new at C++ so can''t figure it out why is it so different.
Any idea?
-O是优化编译器标志。
有了...编译时间稍微长一些,但可执行文件更小,运行速度更快。
-O2可以提供更好的优化。
-O3给出了更好的优化,但是可执行文件比(-b
千字节)更大,而不是-O2。
发布时一个程序,你应该总是用-O2或-O3
(可能是-fomit-frame-pointer)。
-O is the "optimization compiler flag".
With that... the compilation time is a bit longer, but executables are
smaller and run much faster.
-O2 gives even better optimizations.
-O3 gives yet even better optimizations, but executables greater (in
kilobytes) than with -O2.
When releasing a program you should always compile it with -O2 or -O3
(and probably -fomit-frame-pointer).
这篇关于使用-O选项进行编译可以提供不同的运行时间!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!