|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to calculate compilation time using c?
is there function with library "time.h" to calculate the processing time of the code?
|
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
As in, can you find out inside the code itself how long the same code to compile?
Or do you just want to time shell commands like cc externally? |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
no, i just want to measure the performance of my code "using c" so i want how much time it take to process my code i used that Code:
#include <time.h>
clock_t start, end;
double cpu_time_used;
start = clock();
... /* Do the work. */
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;it was so weird since i printed cpu_time_used like that Code:
printf(cpu_time_used) it gave me error Code:
printf("%f",cpu_time_used)gave me 0.0000000000 which is wrong Code:
printf("%i",cpu_time_used)gave me 176543867 which is integer that print double make no since O.o |
|
#4
|
|||
|
|||
|
%i and %d mean integer, float or double would be %f. I usually use this code: Code:
#include <sys/time.h>
#include <sys/types.h>
#include <stdio.h>
/* returns a timestamp in microseconds */
int64_t micro(void)
{
int64_t val;
struct timeval tv;
gettimeofday(&tv, NULL);
val=tv.tv_sec;
val*=1000000;
val+=tv.tv_usec;
return(val);
} |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
niterobin (12-11-2012) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to calculate time | kasparov | Shell Programming and Scripting | 9 | 11-13-2011 09:07 AM |
| Calculate age of a file | calculate time difference | worm | Shell Programming and Scripting | 10 | 02-15-2011 05:59 AM |
| How to calculate time difference between start and end time of a process! | smarty86 | Shell Programming and Scripting | 16 | 09-03-2010 03:15 PM |
| compute compilation time using script | zainab | Shell Programming and Scripting | 3 | 10-02-2008 07:05 PM |
| calculate time | itik | AIX | 2 | 02-15-2008 01:08 AM |
|
|