473,770 Members | 7,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding the time taken by a function

Hi,

I have written a large program which makes multiple calls to number of
functions (also written by me) of the program. Now, I want to know the
collective time taken by all the calls to a specific function. Is
there any way I can find this time.
Thanks in advance,
Raja Kiran Sandireddy.

Nov 14 '05 #1
11 3257
If you don't care how accurate the results are (and don't need better
precession than just seconds), you can call time() before you call the
function you want to time, and then after it returns call time() again and
subtract the values.

Yaniv

<sr*******@gmai l.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi,

I have written a large program which makes multiple calls to number of
functions (also written by me) of the program. Now, I want to know the
collective time taken by all the calls to a specific function. Is
there any way I can find this time.
Thanks in advance,
Raja Kiran Sandireddy.

Nov 14 '05 #2
Wow, that was a bad typo, precision.

"Yaniv Oliver" <yaniv (at) softlink.com> wrote in message
news:41******** @news.012.net.i l...
If you don't care how accurate the results are (and don't need better
precession than just seconds), you can call time() before you call the
function you want to time, and then after it returns call time() again and
subtract the values.

Yaniv

<sr*******@gmai l.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi,

I have written a large program which makes multiple calls to number of
functions (also written by me) of the program. Now, I want to know the
collective time taken by all the calls to a specific function. Is
there any way I can find this time.
Thanks in advance,
Raja Kiran Sandireddy.


Nov 14 '05 #3
Wow, you both top post, which is a Bad Thing.

Please stop!

"Yaniv Oliver" <yaniv (at) softlink.com> wrote in message
news:41******** @news.012.net.i l...
Wow, that was a bad typo, precision.

"Yaniv Oliver" <yaniv (at) softlink.com> wrote in message
news:41******** @news.012.net.i l...
If you don't care how accurate the results are (and don't need better precession than just seconds), you can call time() before you call the function you want to time, and then after it returns call time() again and subtract the values.

Yaniv

<sr*******@gmai l.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi,

I have written a large program which makes multiple calls to number of functions (also written by me) of the program. Now, I want to know the collective time taken by all the calls to a specific function. Is
there any way I can find this time.
Thanks in advance,
Raja Kiran Sandireddy.



Nov 14 '05 #4
sr*******@gmail .com wrote:
Hi,

I have written a large program which makes multiple calls to number of
functions (also written by me) of the program. Now, I want to know the
collective time taken by all the calls to a specific function. Is
there any way I can find this time.
Thanks in advance,
Raja Kiran Sandireddy.


You are essentially profiling the application. Depending on your
implementation, you can use an appropriate profiler.

On most gnu systems, you can use gprof for profiling.
Nov 14 '05 #5
On Mon, 24 Jan 2005 11:50:46 +0200, Yaniv Oliver wrote:
If you don't care how accurate the results are (and don't need better
precession than just seconds), you can call time() before you call the
function you want to time, and then after it returns call time() again and
subtract the values.


clock() tends to be better suited for measuring CPU time. However even
that will have limited resolution so quick functions will probably end up
as 0 difference most of the time. As mentioned elsewhere a profiler would
be a good placed to start.

Lawrence

Nov 14 '05 #6
You can also use gettimeofday function

Subhash

Nov 14 '05 #7
On 24 Jan 2005 05:41:19 -0800, in comp.lang.c , "Subhash"
<su************ @gmail.com> wrote:
You can also use gettimeofday function


Thats not a c function, its a posix one, and may not be available. Besides,
it would be offtopic here.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Nov 14 '05 #8
Lawrence Kirby <lk****@netacti ve.co.uk> wrote:
On Mon, 24 Jan 2005 11:50:46 +0200, Yaniv Oliver wrote:
If you don't care how accurate the results are (and don't need better
precession than just seconds), you can call time() before you call the
function you want to time, and then after it returns call time() again and
subtract the values.

clock() tends to be better suited for measuring CPU time. However even
that will have limited resolution so quick functions will probably end up
as 0 difference most of the time.


[OT]
If you assume that a computer is a stochastic machine, ie. function calls
are delayed in random fashion (I think it is a safe bet for ordinary
desktop computers - it's enough to move your mouse every now and then),
then statistically you could measure the time a function is executed
which is below the resolution of the time measurement if you have
enough samples (in theory at least, but it worked for me in the past
in another language).

--
Stan Tobias
mailx `echo si***@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #9
You can use the clock() function to calculate the time. Just call it
before and after the function calls and substract the two values and
devide it buy CLK_TCK which is the systems pulse time.

eg:
#include<time.h >
//other include files

void main()
{clock_t start, end;

//codes.......... ......

start=clock();
//your funcrion calls
end =clock();
printf("\n Time taken is %f seconds.\n",(en d-start)/CLK_TCK);
}

for more information use the help files in your compiler. (I used the
Turbo c++ compiler for this).

Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3215
by: Graeme Longman | last post by:
Hi everyone, I was wondering if anyone has written some Python code which uses a start date and end date and a given interval (day, month or year) and outputs all the time periods for that range and interval. For example you may wish to find all the months between the dates '2004-02-14' and '2004-08-04'. You would maybe use a function where you pass in those starting and ending dates and the interval 'month' and you'd get back a list...
1
4335
by: Simon Wadsworth | last post by:
My application uses VB6 WebClasses to handle the UI, so all requests come in via a stub ASP page. I would like to know the time taken for the request to be processed. I am trying to use the time-taken value in the IIS log files by I am unclear as to the precise meaning of the value recorded. Using a test WebClass on a development PC (Win2K Pro/SP4) the value recorded in the IIS log files seems to vary:
6
1534
by: Mike | last post by:
Hi, I teach a VB .NET class, and one of the students obviously cheated on the final exam (which was to write a Tic Tac Toe game). They were smart enough to change all of the variables from the program that was copied, though, and I'm having a difficult time finding the original source. Can anyone suggest a place that would let me search their database of codes for snips of code, or something like that? I'm hesitant to post
5
4125
by: raybakk | last post by:
Hi there. If I make a function in c (I acually use gnu right now), is there any way to find out how many clocksycluses that function takes? If I divide some numbers etc Var1 = Var2/Var3, is it a fix amount of clocksycluses that is been used for that division, or does it varies? Raymond
0
2165
by: U S Contractors Offering Service A Non-profit | last post by:
This Sunday the 26th 2006 there will be Music @ Tue Nov Inbox Reply Craig Somerford to me show details 9:54 pm (26 minutes ago) #1St "CLICK" HeAt frOm A blanket --http://mail.google.com/mail/?realattid=f_3n2tmv&attid=0.1&disp=inline&view=att&th=10f0d56e8cb478be 24 oct 2006
4
1461
by: mattG | last post by:
I have a scenario where I have these things that take up (x) number of space. I know the max number of space I will ever have is 512. I am trying to figure out a way to write a formula or whatever will make it work to tell me how many of these things I can put in this space. So example I want to put 60 of these thing that take up (21) units each. Well given that I cannot go over 512 the max I am able to put in any one space is 29. ...
0
2208
by: elpy | last post by:
Hello, I am running a web site using tomcat 6.0 and am having a problem where tomcat's cpu utilization goes up to 95-97% and the response time for even simple page loads becomes very slow. If I use the manager app and reload a couple of webapps the load will drop back down to the usual 10% cpu utilization. I presume that I have a bug somewhere in my code that is starting to "spin" and eat up cpu time. Nothing on the site should take more than a...
3
4249
by: lucky33 | last post by:
My employer has asked me to create a database that will keep track of the employee attendance. Time off / Time earned, excused / unexcused, etc. At my company from the 6th month of employment to the second year you earn 8 hours of PTO each month, from the 2nd to 4th year you earn 10 hours PTO each month. My question is how would I preform a check for each employee once a month to automatically add their newly earned PTO time?
275
12392
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.