Connecting Tech Pros Worldwide Forums | Help | Site Map

how to know the time taken to complete a program?

Newbie
 
Join Date: Oct 2007
Posts: 4
#1: Oct 8 '07
I want to know how we can calculate the time taken for the compilation of a program...pls help..

Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#2: Oct 8 '07

re: how to know the time taken to complete a program?


Check out this function.
sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#3: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by Ganon11

Check out this function.

You know how to tell when you're too tired to be at work? You look at the URL and think, "What the hell is the C Lock function?" And realize only by noticing 'ctime' that it's "clock".

Okay, let's see if I can get away with sleeping in my cube.
Newbie
 
Join Date: Oct 2007
Posts: 4
#4: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by Ganon11

Check out this function.

Actually i want to know the compilation time of a c++ program...could u pls tell me how can i use the function clock....
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by RajuRaman

Actually i want to know the compilation time of a c++ program...could u pls tell me how can i use the function clock....

Some compilers are kind enough to tell you such details or maybe you are writing a C++ compiler using C++?
Newbie
 
Join Date: Oct 2007
Posts: 4
#6: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by r035198x

Some compilers are kind enough to tell you such details or maybe you are writing a C++ compiler using C++?

Ya I am writing a C++ program...and i tried the below program


#include<time.h>
#include<stdio.h>
#include<dos.h>
int main(void)
{
clock_t start , end;
start=clock();
delay(2000);
end= clock();
printf("the time was: %f \n",(end-start/CLK_TCK_;
return 0;
}

but this doesnt give the proper time..its giving the time after i press RUN..
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,195
#7: Oct 8 '07

re: how to know the time taken to complete a program?


What's your interest in knowing the compilation/link time?

The only times when it has ever been an issue in my carrier it has been acceptable to time it by hand using a trust wrist watch and just noting the approximate start and end times, i.e. normally people only care when the time is long enough to measure inaccurately with knowing the exact start and stop times.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#8: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by RajuRaman

Ya I am writing a C++ program...and i tried the below program


#include<time.h>
#include<stdio.h>
#include<dos.h>
int main(void)
{
clock_t start , end;
start=clock();
delay(2000);
end= clock();
printf("the time was: %f \n",(end-start/CLK_TCK_;
return 0;
}

but this doesnt give the proper time..its giving the time after i press RUN..

1.) Use code tags when posting code
2.) That won't give you compilation time. Compilation time by the way will be different on different compilers and platforms. You need to give a C++ source file as an argument to a compiler that you have access to so that you then measure the start and stop time of the compilation process that you will have manually started.
Newbie
 
Join Date: Oct 2007
Posts: 4
#9: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by Banfa

What's your interest in knowing the compilation/link time?

The only times when it has ever been an issue in my carrier it has been acceptable to time it by hand using a trust wrist watch and just noting the approximate start and end times, i.e. normally people only care when the time is long enough to measure inaccurately with knowing the exact start and stop times.

My interest is that..I hav 2 C++ programs....and I want to know which one will take less time...and choose the best between the two...and the time is in milli seconds..which cannot b noted using a wrist watch..
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#10: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by Banfa

What's your interest in knowing the compilation/link time?

The only times when it has ever been an issue in my carrier it has been acceptable to time it by hand using a trust wrist watch and just noting the approximate start and end times, i.e. normally people only care when the time is long enough to measure inaccurately with knowing the exact start and stop times.

Only use I can think of it is when one is making a C++ compiler wants to test their compiler's compilation speed.
I'm of the opinion that writing a C++ compiler is actually useless in itself so there.
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,195
#11: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by r035198x

I'm of the opinion that writing a C++ compiler is actually useless in itself so there.

That rather depends on if you are manufacturing a new processor or not. If you are creating a new processor then not creating a compiler for it is going to somewhat limit it's use :D
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#12: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by RajuRaman

My interest is that..I hav 2 C++ programs....and I want to know which one will take less time...and choose the best between the two...and the time is in milli seconds..which cannot b noted using a wrist watch..

Take a deep breadth.
Now read this:
Compilation time is different from running time.

A fast program is not a program that takes a short time to compile. It is one that takes a short time to run.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#13: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by Banfa

That rather depends on if you are manufacturing a new processor or not. If you are creating a new processor then not creating a compiler for it is going to somewhat limit it's use :D

Thankfully I don't fiddle around with such stuff anymore.
Of course creating a processor is not entirely useless so I take back half of my ealier remark.
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,195
#14: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by r035198x

A fast program is not a program that takes a short time to compile. It is one that takes a short time to run.

Actually almost certainly the reverse, optimisation takes far longer than actual compilation of the code so if you where to switch off the optimisation in your compiler you will almost certainly end up with a program that compiles faster.

However optimised code almost always runs faster than un-optimised code so if you switch off the optimiser you will almost certainly end up with a program that runs slower.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#15: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by Banfa

Actually almost certainly the reverse, optimisation takes far longer than actual compilation of the code so if you where to switch off the optimisation in your compiler you will almost certainly end up with a program that compiles faster.

However optimised code almost always runs faster than un-optimised code so if you switch off the optimiser you will almost certainly end up with a program that runs slower.

So how is my comment the reverse of this?
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,195
#16: Oct 8 '07

re: how to know the time taken to complete a program?


Quote:

Originally Posted by r035198x

So how is my comment the reverse of this?

Sorry I meant your statement did not go far enough, a short compile time is likely to mean a long run time and vice versa.
Reply


Similar C / C++ bytes