473,948 Members | 14,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I know how long my function call took?

Hello all. I am interfacing my computer to the outside world for an
experiment and we would like to know how much time the calling function
takes. The specs say this should happen on the order of a microsecond,
which is faster than we need. We would like to call 30 or so of these
functions in 0.5 milliseconds and before committing to purchasing this
interface system, we would like to make sure it fits our needs. However,
we are having difficulties timing how long our functions take. We are
running Microsoft Visual Developer (using C) v 6.0 on a computer running
Win98. We tried something like the following

#include <time.h>
clock_t start, end;
double duration;
start=clock();
my_function_to_ test();
stop=clock();
duration=(stop-start)/CLOCKS_PER_SEC;

It has become apparent that the resolution of clock() is only on the
order of a second. I have tried looking at the C FAQ and Google to find
something that would give me better resolution, but have failed. We are
thinking of looping our test function thousands or millions of times and
dividing the total duration by the total number of loops, but I would
like to get a better idea how long each function will take.

Thanks in advance

Kevin
Nov 15 '05 #1
4 2515
>Hello all. I am interfacing my computer to the outside world for an
experiment and we would like to know how much time the calling function
takes.
A function call always takes at least two moments (a term *NOT*
defined by the ANSI C standard). That way, another program (if
there is one) has a chance to do something else in between them,
usually with the effect of messing things up.
#include <time.h>
clock_t start, end;
double duration;
start=clock( );
my_function_to _test();
stop=clock() ;
duration=(st op-start)/CLOCKS_PER_SEC;
clock_t is probably an integer type.
The above division is INTEGER DIVISION!

duration=(stop-start)*1.0/CLOCKS_PER_SEC;
It has become apparent that the resolution of clock() is only on the
order of a second.


Maybe, maybe not, but your division lost the fractional part, if
there ever was one.

Gordon L. Burditt
Nov 15 '05 #2
Gordon Burditt wrote:
Hello all. I am interfacing my computer to the outside world for an
experiment and we would like to know how much time the calling function
takes.

A function call always takes at least two moments (a term *NOT*
defined by the ANSI C standard). That way, another program (if
there is one) has a chance to do something else in between them,
usually with the effect of messing things up.


Thanks for the quick response, but what do you mean as a moment (aside
from each person's subjective notion of time).
#include <time.h>
clock_t start, end;
double duration;
start=clock() ;
my_function_t o_test();
stop=clock( );
duration=(sto p-start)/CLOCKS_PER_SEC;

clock_t is probably an integer type.
The above division is INTEGER DIVISION!

duration=(stop-start)*1.0/CLOCKS_PER_SEC;

It has become apparent that the resolution of clock() is only on the
order of a second.

Maybe, maybe not, but your division lost the fractional part, if
there ever was one.

Gordon L. Burditt

Nov 15 '05 #3
# It has become apparent that the resolution of clock() is only on the
# order of a second. I have tried looking at the C FAQ and Google to find

Given some of the hardware out there, be happy it's that small.

# something that would give me better resolution, but have failed. We are
# thinking of looping our test function thousands or millions of times and
# dividing the total duration by the total number of loops, but I would
# like to get a better idea how long each function will take.

You probably have system specific clock functions with millisecond,
microsecond, or nanosecond resolutions. Not ANSI C, but probably
available anyway.

Note that with virtual memory and multiprocessing , high precision clocks
can wobble quite a bit even with the same code and data.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
GERBILS
GERBILS
GERBILS
Nov 15 '05 #4
Kevin Schultz wrote:

Hello all. I am interfacing my computer to the outside world for an
experiment and we would like to know how much time
the calling function
takes. The specs say this should happen on the order of a microsecond,
which is faster than we need. We would like to call 30 or so of these
functions in 0.5 milliseconds and before committing to purchasing this
interface system, we would like to make sure it fits our needs.
However,
we are having difficulties timing how long our functions take. We are
running Microsoft Visual Developer (using C) v 6.0 on a computer running
Win98. We tried something like the following

#include <time.h>
clock_t start, end;
double duration;
start=clock();
my_function_to_ test();
stop=clock();
duration=(stop-start)/CLOCKS_PER_SEC;

It has become apparent that the resolution of clock() is only on the
order of a second. I have tried looking at the C FAQ and Google to
find something that would give me better resolution, but have failed.
We are
thinking of looping our test function thousands or millions of times
and
dividing the total duration by the total number of loops, but I would
like to get a better idea how long each function will take.


Time your thousand million loops with the function call,
and then time a thousand million empty loops and subtract
the empty loop time from call loop time.

--
pete
Nov 15 '05 #5

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

Similar topics

11
1964
by: Daniel Wilcox | last post by:
I have a question, I have been given a piece of code that apparantly compiles under Visual C++ but I cannot get to compile under g++ 3.2. I have read the FAQ and delved into the Stroustrup book as well as an O'Reilly one but please I am not a natural C++ programmer so allow me some scope to commit some no-brainers as it were ;)
36
5480
by: HERC777 | last post by:
just paste the below into notepad, call it iqsort.html double click it and your IE browser will run it. (neat! a universal programming language we can all run!) it falls out from the sort procedure. I got javascript quicksort running, it's quick but it gets stack overflow after about 5000 elements. Am I passing the array as a parameter alright? I think javascript default is to pass pointers, that can be global.
2
2639
by: tom horner | last post by:
Any ideas on why drop and create alias statements would take a long time? We recently went through an upgrade of our production database, which included alter statements to table structures, create tables, drop tables, and data inserts, deletes, and updates. Also, we dropped and recreated all the alias's we had on the tables and views to those tables. We are on UDB 7.2, FP7, on AIX. Everything took about the same time as in our...
72
3675
by: ravi | last post by:
I have a situation where i want to free the memory pointed by a pointer, only if it is not freed already. Is there a way to know whether the memory is freed or not?
0
1829
by: Rahul Chatterjee | last post by:
Hello All I have designed a dotnet application using VB which basically takes a selection and passes value to a crystal report which in turn passes the value to a Stored procedure. After the report gets generated it is PDF'ed - all this is done thru a single click in my program. Now the catch here is that through the program all these tasks of generating the report and PDF'ing 1400 records (about 25 pages) takes 15 minutes.
37
4037
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as a function
17
2374
by: Navaidstech | last post by:
Hi all... I'm new to Java programming. I've seen how finicky java is as far case and space sensitivity sensitivity is concerned. However, I'm slowly getting hang of it. I came accross this weird problem that I just can't figure out. First of all, here is a link to the script: http://www.ve3gop.com/aprs/
11
1187
by: vinnie | last post by:
I'm a self learner, and i'm trying to figure out how this code should work. What is not clear to me, is why the function InsertNumber is called 3 times: wasn;t easier to call it just once and put all together? There is a call to that function at line 8, 13, 17 1 namespace riprova 2 { 3 public class Program
8
2574
by: jr | last post by:
I have an application the makes a call to a webservice to retrieve some additional info for my app. The information I get back is non-essential, so I do NOT want my entire app hanging to wait for this repsonse if it takes more than, say, 2 seconds to a response from the webserver. Basically, how would I immediately end a function that is taking too long to respond? --
0
10164
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
9986
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
10694
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8256
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7431
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
6118
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...
1
4948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4540
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3544
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.