Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Execution time in a C program

Status
Not open for further replies.

pinkyvidya

Member level 2
Joined
Sep 9, 2009
Messages
49
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,288
Location
kerala
Activity points
1,655
Inorder to find execution time in C program, I have used the following piece of code

1.
#include <stdio.h>
2.
#include <time.h>
3.

4.
clock_t start = clock();
5.
/* Code you want timed here */
6.
printf("Time elapsed: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);


and it is working..I would like to know whether the time it is showing is in seconds or milliseconds

Kindly someone please help. I will bw very thankful
 


pinkyvidya said:
I would like to know whether the time it is showing is in seconds or millisecondsl

time will be in seconds

Declaration: clock_t clock(void);
Remarks: clock can be used to determine the time interval between two events.

To determine the time in seconds, divide the value returned by clock by the value of the macro CLK_TCK. (CLOCKS_PER_SEC)

Return Value:
  • On success, returns the processor time elapsed since the beginning of the program invocation.
  • On failure (the processor time is not available, or its value can't be represented), returns -1.
hope this helps

regards
bassa
 

Thanks for your valuable reply.....................

@ amraldo

But you should take care of wrapping.

Have you ever though of using a profiler?



I am begineer in C field. So I am not aware of wrapping. Also I am using NIOS2 soft processor and using Nios 2 Instruction Set Simulator. I am new to that tool. So I don't know how to use that profiler. Can you just tell me how to use any kind of profiler to extract profiling datas? Thanks in advance.......
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top