🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.internals
2 messages
2 total messages Started by Erik Cickovskis Mon, 02 Nov 1992 07:12
Measuring the time of a function
#1451
Author: Erik Cickovskis
Date: Mon, 02 Nov 1992 07:12
25 lines
1326 bytes
Is it possible to evaluate the time a function needs to execute in
C and UNIX?

For my thesis I am writing C programms doing some mathematical
optimaziation stuff. I would like to know what time a function
needs, which executes the critical calculations.

The problem is, now, that the functions in consideration need
about some milliseconds to execute, and I need to be quite
accurate.

So what can I do to prevent kernel execution time to be measuered
with my function execution time. I thougt about it a lot and tend
to think it is impossible in a time sharing environment, but who
knows...

Realise that I don't want the whole programm to be timed, just
one function in it.

Any hints welcome, Erik
-- 
------------------------------------------------------
Erik Cickovskis            erik@sfb313.uni-kiel.dbp.de
------------------------------------------------------
Re: Measuring the time of a function
#2383
Author: Suresh .S
Date: Wed, 18 Nov 1992 20:12
68 lines
2836 bytes
Erik Cickovskis (erik@sfb313.uni-kiel.dbp.de) wrote:
: 
: Is it possible to evaluate the time a function needs to execute in
: C and UNIX?
: 
: For my thesis I am writing C programms doing some mathematical
: optimaziation stuff. I would like to know what time a function
: needs, which executes the critical calculations.
: 
: The problem is, now, that the functions in consideration need
: about some milliseconds to execute, and I need to be quite
: accurate.
: 
: So what can I do to prevent kernel execution time to be measuered
: with my function execution time. I thougt about it a lot and tend
: to think it is impossible in a time sharing environment, but who
: knows...
: 
: Realise that I don't want the whole programm to be timed, just
: one function in it.

U can get the timing in the user  space execution alone, avoinding the
kernel execution ..

You can use a utility called "prof" and gnu  has it as "gprof"(correct
me if I am wrong), to use this do the following. We have "cc" and that
gives us this option

(1) When you compile, do it with a  "-p" option, and  when you execute the
program it will create a file called "mon.out".

Now do "prof <name_of_executable>" and that will give u timings of all
the functions in the program. I don't how accurate this is ..

(2) Another option is to use  the "times()" system  call, here you can
get  seperate  the execution in "user  land" and "kernel land", of any
particular function ..

------------------------CUT HERE-------------------------------------
# include  <stdio.h>
# include <sys/types.h>
# include <sys/times.h>
 
 struct tms buffer1,buffer2;
 long count1,count2;
 long times();
 
main()
{ 
   int i,j;
 
  
   count1 = times(&buffer1);

 /* Here you call the function */

   count2 = times(&buffer2);
 
printf("User: %.2f\nSystem: %.2f \n", (float)(buffer2.tms_utime -  buffer1.tms_utime)/60,(float)(buffer2.tms_stime -  buffer1.tms_stime)/60);
}
------------------------------------------------------------------------

Hope that helps, let me know if you get any other solution also ..

-- 
Suresh Sivaprakasam                    
Department of Computer Science,    SUNY Buffalo,    Amherst,   NY - 14260-0001
Internet :sivap-s@cs.Buffalo.EDU               Bitnet : sivap-s@SUNYBCS.BITNET
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads