闲来无聊,写了三个程序
java版
package com;
public class myHello {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long a = System.currentTimeMillis();
for(long i=0;i<10000000;i++)
{
System.out.println(i+"Hello,world!");
}
long b = System.currentTimeMillis();
System.out.println(b-a);
}
}
我觉得这个应该很慢,但是我想比一下它跟C#哪一个更慢。于是又写了c#版
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationTest
{
class Program
{
static void Main(string[] args)
{
long a = System.DateTime.Now.Ticks;
for (long i = 0; i < 10000000; i++ )
{
System.Console.WriteLine("Hello,world");
}
long b = System.DateTime.Now.Ticks;
System.Console.WriteLine(b-a);
}
}
}
两个程序并不多同时跑完了,结果java的运行完了,c#的还在跑啊跑啊跑啊,跑了半天还没跑玩,于是我就关了,又写了个C++版的。C++版
#include "stdafx.h"
#include "iostream"
#include<windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
long a = GetTickCount();
for(long i=0;i<10000000;i++)
{
std::cout<<i<<"Hello,world!\n";
}
long b = GetTickCount();
std::cout<<b-a;
return 0;
}
我想,C++应该跑得比java的快,于是就把跑C++的,再F11 java的。结果java的跑完了,C++的还在跑啊跑啊跑啊,关天没跑完。不知道是我跑的方法不对,比如C++的优化开关没有打开,编译选项没有设置对。上图,在等待c++和C#跑完的漫长过程。
今天是第一次在csdn上写博客。