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

Function Timer in C

I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..

Apr 5 '07 #1
9 4490
yo*********@gmail.com wrote:
I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..
Try comp.lang.c. When you do, make the question a bit clearer, what do
you want to time?

--
Ian Collins.
Apr 5 '07 #2
yo*********@gmail.com wrote:
I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..
Look up the clock() function (usually declared in <time.t>):

man clock
Apr 6 '07 #3
Larry Smith wrote:
yo*********@gmail.com wrote:
>I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..

Look up the clock() function (usually declared in <time.t>):
<ctime or <time.h>
man clock
and woman what?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 6 '07 #4
Victor Bazarov wrote:
Larry Smith wrote:
>yo*********@gmail.com wrote:
>>I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..
Look up the clock() function (usually declared in <time.t>):

<ctime or <time.h>
> man clock

and woman what?

V
Well gee, thanks for correcting the typing error.

'man' - FYI for Windows folks, that's the Unix manual viewer
command.

Ian posted from Solaris, and I mistakenly viewed his
email headers, instead of the OP's headers, when replying.

Thanks for the gracious corrections.
Apr 6 '07 #5
<yo*********@gmail.comwrote in message
news:11*********************@w1g2000hsg.googlegrou ps.com...
>I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..
I generally just use clock().

unsigned int Start = clock();
MyFunction();
unsigned int End = clock();
std::cout "Elapapsed time: " << End - Start << " ns" << "\n";

Modify to taste. I think it's ms. On my system it's 1/1000 of a second.
Apr 6 '07 #6
On Apr 6, 7:06 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
<yoviesma...@gmail.comwrote in message
news:11*********************@w1g2000hsg.googlegrou ps.com...
I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..
I generally just use clock().
unsigned int Start = clock();
MyFunction();
unsigned int End = clock();
std::cout "Elapapsed time: " << End - Start << " ns" << "\n";
Modify to taste. I think it's ms.
It's CLOCKS_PER_SECOND. Posix requires CLOCKS_PER_SECOND to be
1000000, but it may vary on other systems. The best way to
write the above would be:

std::cout << "Elapapsed time: "
<< double( End - Start ) / CLOCKS_PER_SEC * 1000.0
<< " ms" << std::endl ;
On my system it's 1/1000 of a second.
In the old days, 50 or 60 used to be frequent values.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 6 '07 #7
Thanks for all ...

Apr 9 '07 #8
On Apr 6, 1:06 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
<yoviesma...@gmail.comwrote in message

news:11*********************@w1g2000hsg.googlegrou ps.com...
I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..

I generally just use clock().

unsigned int Start = clock();
MyFunction();
unsigned int End = clock();
std::cout "Elapapsed time: " << End - Start << " ns" << "\n";

Modify to taste. I think it's ms. On my system it's 1/1000 of a second.
On most systems it is a millisecond. I use std::clock() as well,
margin of error of close to 10 milliseconds, though. You could also
use gprof or a similar profiler.

Apr 9 '07 #9
On Apr 9, 4:11 am, "Siddhartha Gandhi" <siddharthagandhi...@gmail.com>
wrote:
On Apr 6, 1:06 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
<yoviesma...@gmail.comwrote in message
news:11*********************@w1g2000hsg.googlegrou ps.com...
>I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..
I generally just use clock().
unsigned int Start = clock();
MyFunction();
unsigned int End = clock();
std::cout "Elapapsed time: " << End - Start << " ns" << "\n";
Modify to taste. I think it's ms. On my system it's 1/1000 of a second.
On most systems it is a millisecond.
On all systems, it's CLOCKS_PER_SEC. Other than that, the only
"standard" I know is Posix, which requires a value of 1000000
for CLOCKS_PER_SEC, i.e. microseconds. (Linux is also Posix
conform in this respect.)
I use std::clock() as well,
margin of error of close to 10 milliseconds, though.
Historically, the granularity was the number of ticks. This
certainly isn't the case today, and I don't know of any system
which really gives microsecond granularity. (Historically, on
the first systems I used, CLOCKS_PER_SEC was 50 in Europe, and
60 in America. Which was the granularity.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 10 '07 #10

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

Similar topics

5
by: Vedran Furac | last post by:
How can I call a function every time a specified number of milliseconds elapses? Javascript has setInterval() function and I need something like that. Currently I use this: def function(): t =...
1
by: pvdm | last post by:
Hi, I am writing an app which encapsulates a multimedia timer. I implemented a TimerProc as static member function and a static member variable pThis as pseudo this variable to access in the...
36
by: lauren quantrell | last post by:
I'm hoping someone can tell me if there is any performance benefit in my applications between distinguishing a code routine as a Function or a Sub or if there is a performance benefit between...
17
by: Razzel | last post by:
I created this as a test: #include <time.h> main(){ printf(X1: %s\n", putim()); printf(X2: %s\n", putim()); } putim() { time_t t; time(&t); return(ctime(&t));
1
by: CES | last post by:
All, I was wondering if someone could point me to a tutorial on creating & accessing functions from within a wrapper function. I've created a group of functions related to a timer event. All...
11
by: Russ | last post by:
I have a couple of questions for the number crunchers out there: Does "pow(x,2)" simply square x, or does it first compute logarithms (as would be necessary if the exponent were not an integer)?...
2
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy...
1
by: remya1000 | last post by:
I'm using VB.NET. in VB6 we have a function called Timer, which returns a Single value that represents the number of seconds that have elapsed since midnight. for eg: lngStartTimer =...
2
by: WGW | last post by:
Hello all, I need another set of eyes cause it just isn't working, no matter how identical I make it. The initRotator function works when called by itself, but when adding another function, only the...
12
by: Zytan | last post by:
I have a Timer class set to trigger every second. The Tick function that is called every second uses a lock to prevent multiple ticks from executing the same code at the same time. The code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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...

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.