473,382 Members | 1,357 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,382 software developers and data experts.

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 2489
>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=(stop-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_to_test();
stop=clock();
duration=(stop-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
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...
36
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...
2
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,...
72
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
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...
37
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...
17
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...
11
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...
8
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.