|
|

楼主 |
发表于 2008-2-25 22:47:28
|
显示全部楼层
I composed a simple program using cpp- //compile_time_test.cc
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <string>
- using namespace std;
- int main()
- {
- clock_t start;
- clock_t finish;
- string compile_flag[6] = {
- "-O2 -march=pentium-m -pipe -fomit-frame-pointer",
- "-O2 -march=native -pipe -fomit-frame-pointer",
- "-O2 -march=pentium-m -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse",
- "-O2 -march=native -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse",
- "-O3 -march=pentium-m -pipe -fomit-frame-pointer",
- "-O3 -march=native -pipe -fomit-frame-pointer"
- };
- string command = "g++ -c compile_time_test.cc ";
- string cmd;
- for ( unsigned int flg = 0; flg < 6; ++flg )
- {
- cmd = command + compile_flag[flg];
- start = clock();
- for ( unsigned int i = 0; i < 100; ++i )
- {
- system( cmd.c_str() );
- }
- finish = clock();
- long double duration = static_cast<long double>
- ( finish - start ) / CLOCKS_PER_SEC;
- cout << "It costs "<< duration
- << " second(s) to compile compile_time_test.cc 100 times using flag "
- << compile_flag[flg] << ".\n";
- }
- return 0;
- }
复制代码
and the resultIt costs 0 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=pentium-m -pipe -fomit-frame-pointer.
It costs 0.01 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=native -pipe -fomit-frame-pointer.
It costs 0 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=pentium-m -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse.
It costs 0.01 second(s) to compile compile_time_test.cc 100 times using flag -O2 -march=native -pipe -fomit-frame-pointer -msse2 -mmmx -mfpmath=sse.
It costs 0.05 second(s) to compile compile_time_test.cc 100 times using flag -O3 -march=pentium-m -pipe -fomit-frame-pointer.
It costs 0.07 second(s) to compile compile_time_test.cc 100 times using flag -O3 -march=native -pipe -fomit-frame-pointer. |
|