Timmy Lacoste
2011-12-07 17:27:58 UTC
Java took about 16 seconds to run the for loop, but c++ took over an hour.
i was wondering if i did something wrong, or if i should switch the compiler, if so please reccomend a good free one.
My java code is as follows:
//import java.util.*;
public class Time
{
public Time(){}
public static void main(String args[])
{
long startTime = System.currentTimeMillis();
Time ext=new Time();
ext.callMethod();
long endTime = System.currentTimeMillis();
System.out.println("Total elapsed time in execution of method callMethod() is :"+ (endTime-startTime));
}
public void callMethod(){
System.out.println("Calling method");
for(int i=1;i<=1000000;i++)
{
System.out.println("Value of counter is "+i);
}
if you have suggestion for the code please comment.
for c++:
#include
#include
#include
using namespace std;
int main()
{
clock_t start, end;
start = clock();
int i;
for(i=0; i<1000000+1; i+=1){
system("Cls");
cout<< i << endl;}
end = clock();
cout << "Time required for execution: "
<< (double)(end-start)/CLOCKS_PER_SEC
<< " seconds." << "\n\n";
Sleep(10000);
return 0;
}
please give suggestions. Thank You!!!