因为Java是解释执行的,所以,几乎所有的教科书都说,Java比C++运行速度慢!可是,实际上,是这样的吗?实践是检验真理的唯一标准。
实验环境:硬件:Intel i5 3230M双核处理器,2.6GHz 4GB DDR3内存 软件:Linux Ubuntu14.04 / Codeblocks / Eclipse
C++ code:
#include
#include
#include
using namespace std;
/*
* Test C++ running speed
*/
int main()
{
int i,j;
double d =0;
int limit =6;
clock_t start , finish;
// begins
start =clock();
for(i=0;i
for(j=0;j<10000;j++)
d = d + 0.001;
finish =clock();
// output
double time = ( finish - start ) * 1000.0 / CLOCKS_PER_SEC ;
cout<
return 0;
}
实验结果: 1780ms(平均值)
Java code:
/*