How to calculate compilation time using c? | Unix Linux Forums | Programming

  Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

How to calculate compilation time using c?

Programming


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-10-2012
fwrlfo fwrlfo is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 30 December 2013, 9:58 AM EST
Posts: 29
Thanks: 16
Thanked 1 Time in 1 Post
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  
Old 12-10-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 22 October 2014, 6:34 PM EDT
Location: Saskatchewan
Posts: 19,649
Thanks: 818
Thanked 3,341 Times in 3,130 Posts
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  
Old 12-10-2012
fwrlfo fwrlfo is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 30 December 2013, 9:58 AM EST
Posts: 29
Thanks: 16
Thanked 1 Time in 1 Post
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  
Old 12-10-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 22 October 2014, 6:34 PM EDT
Location: Saskatchewan
Posts: 19,649
Thanks: 818
Thanked 3,341 Times in 3,130 Posts
%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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 09:39 PM.