linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mehran Rezaei <mehran@cs.unt.edu>
To: C news group <linux-c-programming@vger.kernel.org>,
	gcc news group <linux-gcc@vger.kernel.org>
Subject: timing
Date: Wed, 01 May 2002 11:51:22 +0000	[thread overview]
Message-ID: <aap6j9$9uv$2@main.gmane.org> (raw)

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


             reply	other threads:[~2002-05-01 11:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-01 11:51 Mehran Rezaei [this message]
     [not found] <3CCFD6BA.1D667C11@cs.unt.edu>
2002-05-01 18:20 ` timing Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='aap6j9$9uv$2@main.gmane.org' \
    --to=mehran@cs.unt.edu \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=linux-gcc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).