473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Code for caluculating the execution time of C program

Hi,
I require code for caluculating the execution time of C program .Can anybody help regarding this.

Regards,
Kameswari
Jun 21 '06 #1
6 41082
Banfa
9,065 Expert Mod 8TB
Well that rather depends on what operating system you use. On a multitasking operating system like *nix and Windows (and several others) there is no generic way to measure the execution time from the program itself. You can measure the execution start time and the execution stop time however stop - start is not the execution time of the program. It is the execution time of the program plus all the time it was suspend while something else executed.

The only real way to get program execution time on a multi-tasking system is if the operating system provides a way to find out.
Jun 21 '06 #2
shakov
1
Under Linux you can use the time command or for the detailed measure of time consumption of every procedure you can use the program gprof. See:
http://kuscsik.blogspot.com/2007/08/...using-gcc.html
Sep 5 '07 #3
gpraghuram
1,275 Expert 1GB
Hi,
I require code for caluculating the execution time of C program .Can anybody help regarding this.

Regards,
Kameswari
Hi ,
If u need to calculate execution time of the c code...u can use time function
The pseudo code will be like this
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. time_t t1,t2;
  4. time(&t1);
  5. //<your function goes here>
  6. time(&t2);
  7. diff_time(t2,t1)//check for function name
  8. }
  9.  
Thanks
Raghuram
Sep 5 '07 #4
Hi Kamesari

This is sathish. What Raghu stated is fine.

Even me too had a requirement. I tried the program with difftime() and clock() and both were not giving the correct result.


I tried it under Sun Os. But whatever program raghu has given is correct.

Thanks & Regards
Sathish KUmar
Sep 5 '07 #5
hi gpraghuram,
plz give me the code in C required for calculating the time for execution of any function. i m working in linux. the time( ) system call gives the time value in sec. but i need in milisec,or microsec...
help me out
Nov 27 '07 #6
gpraghuram
1,275 Expert 1GB
hi gpraghuram,
plz give me the code in C required for calculating the time for execution of any function. i m working in linux. the time( ) system call gives the time value in sec. but i need in milisec,or microsec...
help me out

Hi,
I dont know C-Library functions available which can give the execution time in Milli/micro seconds.

Raghuram
Nov 28 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
5
by: Johannes Lebek | last post by:
Hi there, lately, I experienced a strange thing on my DB2 V8.1 on Windows: Some queries took a very long time. A snapshot discovered the following: Number of executions = 47...
7
by: Tim Quon | last post by:
Hi Is there any function to get the current time so I can calculate the execution time of my code? What all is in the time.h and sys/times.h? Thanks Tim
27
by: vishnu mahendra | last post by:
cah you please tell me how to find the execution time of a program in c. thank you in advance, vishnu
38
by: vashwath | last post by:
Might be off topic but I don't know where to post this question.Hope some body clears my doubt. The coding standard of the project which I am working on say's not to use malloc.When I asked my...
3
by: vashwath | last post by:
Hi all, I have written program for calculating the execution time of a function.Any critics (on the method of calculating execution time) are welcome. #include <stdio.h> #include <time.h>...
25
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
8
by: Magesh | last post by:
Consider a block, fncall( ); /* tells me the current millisecond or something like that: time-1 */ {/* block of code for which I need to know the exec time ... ... ... } fncall( ); /* tells...
6
by: jainyi | last post by:
Hi, I want to calculate execution time for a program computing fibonacci number in C++. I have programmed two functions (one using recursion and other using divide and conquer huristic) to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.