天空下的雨

用乐观的生活,品味非凡人生。 博客搬家了,欢迎进入新博客:www.sh96.cn
19

今天,在一篇博客文章中说: 打印10万个hello,world,Java比C++快25倍,下面是引用:

#include <iostream>
#include <time.h>
using namespace std;

int main(){
time_t tm;
time_t start_t=time(&tm);
for(int i=0;i<100000;i++){
cout<<"hello,world"<<endl;
}
cout<<"costed:"<<(time(&tm)-start_t);
getchar();
return 0;

}

并在MyEclipse5.5(JDK为1.5)中写了下面的一段Java程序:

public class Test {

public static void main(String[] args)
{
long startPoint=System.currentTimeMillis();

for (int i = 0; i < 100000; i++) {
  
   System.out.println("hello,world");
}
long endPoint=System.currentTimeMillis();
System.out.println("costed:"+(endPoint-startPoint)/1000);
  
  
}
 

}

运行后发现Java程序在打印10万个Hello world的时候竟然只花了三秒。而C++程序则花费了75秒,也就是说在这一点上Java比C++快25倍。呵呵,如果在其它方面Java也能这么快就好了!

 

 

推荐(0)
收藏
分享至:

相关日志

发表评论: