* timing
@ 2002-05-01 11:51 Mehran Rezaei
0 siblings, 0 replies; 2+ messages in thread
From: Mehran Rezaei @ 2002-05-01 11:51 UTC (permalink / raw)
To: C news group, gcc news group
Hello dear all,
For the sake of performance analysis of some programs, I am using
clock() function call. I am running the programs on a linux box (Redhat
7.2, and my machine is i686).
However, I am not getting the correct results as I expected. Perhaps I
miss something necessary for using timing function calls.
Here is a code fragment that I am testing:
/***************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#define TEST 8
main(){
int i=1;
int size=5*8000;
void *pBreak,*newBreak;
time_t time1,time2;
clock_t start,finish,elapsed;
start=clock();
time(&time1);
sleep(10);
1 << i;
for(i=0;i<100;i++){
printf("%x %d\n",-TEST,(1 << i));
if (1 << i == 8192) break;
}
printf("%d \n",size >> i);
i=brk(pBreak);
assert(i == 0);
newBreak=sbrk(1024);
finish=clock();
elapsed=finish-start;
time(&time2);
printf("Exec Time from clock() =
%f\n,(double)(finish-start)/(double)CLOCKS_PER_SEC);
printf("Exec Time from difftime() = %lf\n",difftime(time2,time1));
}
/*****************************************************************************/
To my understanding both printfs should at least show 10 seconds
(because of "sleep(10)"). But they do not.
Note that I am not looking for so called Wall-Clock (total program
execution), for which I can use system calls. I should stick to a
function call that enables me to monitor the execution time of only some
of the functions in my programs (for my specific purpose).
Do you see any problem with my simple program? Is there anyway that I
can get perhaps better resolution on CPU time or elapsed time?
Your help and concern is appreciated.
So long,
Mehran
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: timing
[not found] <3CCFD6BA.1D667C11@cs.unt.edu>
@ 2002-05-01 18:20 ` Glynn Clements
0 siblings, 0 replies; 2+ messages in thread
From: Glynn Clements @ 2002-05-01 18:20 UTC (permalink / raw)
To: Mehran Rezaei; +Cc: C news group, gcc news group
Mehran Rezaei wrote:
> For the sake of performance analysis of some programs, I am using
> clock() function call. I am running the programs on a linux box (Redhat
> 7.2, and my machine is i686).
> However, I am not getting the correct results as I expected. Perhaps I
> miss something necessary for using timing function calls.
[snip]
> To my understanding both printfs should at least show 10 seconds
> (because of "sleep(10)"). But they do not.
clock() reports the amount of CPU time used by the program. sleep()
will use negligible CPU time (probably too small to measure).
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-05-01 18:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-01 11:51 timing Mehran Rezaei
[not found] <3CCFD6BA.1D667C11@cs.unt.edu>
2002-05-01 18:20 ` timing Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).