From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mehran Rezaei Subject: timing Date: Wed, 01 May 2002 11:51:22 +0000 Sender: linux-gcc-owner@vger.kernel.org Message-ID: <3CCFD6BA.1D667C11@cs.unt.edu> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: List-Id: Content-Type: text/plain; charset="us-ascii" 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 #include #include #include #include #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