|
|
发表于 2009-4-30 11:01:11
|
显示全部楼层
你比的是 cout 和 printf,不是 C++ 和 C,C++ 里面同样可以使用 printf...
BTW,用 gettimeofday(); test_function(); gettimeofday(); 来测试得到的结果在很多时候是荒谬的,因为很多函数返回的时候操作还没有真正完成。
Post by Kevin_Chou;1981491
事实说明真像,两个hello world一个c,一个c++的,自己回去make看结果。
cpp:
#include <iostream>
#include <sys/time.h>
using namespace std;
int main() {
struct timieval tp1, tp2;
struct timezone tz;
(&tp1, &tz);
cout << "hello world" << endl;
gettimeofday(&tp2, &tz);
printf("need %u microseconds\n", tp2.tv_usec - tp1.tv_usec);
return 0;
}
c:
#include <stdio.h>
#include <sys/time.h>
int main() {
struct timieval tp1, tp2;
struct timezone tz;
gettimeofday(&tp1, &tz);
puts("hello world");
gettimeofday(&tp2, &tz);
printf("need %u microseconds\n", tp2.tv_usec - tp1.tv_usec);
return 0;
}
手写代码非复制粘贴,如果有语法错误,自己改一下。
我这里的执行结果c程序最好到17,最差到92,稳定在20-30;c++最好到37,最差到127,稳定在40-50。
编译环境: gcc 4.3.3
CPU: Intel Core 2 2.2GHz
RAM: 2GB
欢迎讨论,讨论前请拿出数据。 |
|