linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J." <mailing-lists@xs4all.nl>
To: linux-c-programming@vger.kernel.org
Subject: Re: Start of the time slice
Date: Mon, 5 Jul 2004 14:35:28 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.21.0407051427430.5695-100000@hestia> (raw)
In-Reply-To: <7F11C0CADA50AF4690BF42F715ABFBF86468B1@battaexch22.mol.hu>

On Mon, 5 Jul 2004, [iso-8859-2] Nagy Imre (Vecsés) wrote:
> Dear List,
> 
> Excuse me, my English is limited, but I try to formulate clearly.
> 
> I would like to konw how many unexpired time is in my process. The normal
> time slice (10ms) is enough for me, but I want to get run my function right
> at the start of time slice. 
>         _______________           ______________
> ____ ... 10 ms         __ . . . __  10 ms       ___
> 
>         |my f()                   |my f()
> 
> main()
> 
> {
> .
> 
> while(1) {
>    f();
> }
> .
> 
> Best regards,
> 
> Imre Nagy

I am not quite sure what your question is, but my best guess is that you
are asking how to time parts of your c code ??

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>

#define CPU_TIME (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + \
  ruse.ru_stime.tv_sec + 1e-6 * \
  (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec))

/* get resource limits and usage */
extern int getrusage();
struct rusage ruse;

int main(void) {
 double first, second;
 time_t start, end;

 /* record start time... */
 time(&start);
 first = CPU_TIME;

 /* produce some cpu cycles... */
 /* put your code to be timed here.. */
 /* .... */

 /* end time.. */
 second = CPU_TIME;
 time(&end);

 /* print the results */
 printf("cpu  : %.2f secs\n", second - first); 
 printf("user : %d secs\n", (int)(end - start));
}

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2004-07-05 12:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-05  7:22 Start of the time slice Nagy Imre (Vecsés)
2004-07-05 10:39 ` Glynn Clements
2004-07-05 12:35 ` J. [this message]

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=Pine.LNX.4.21.0407051427430.5695-100000@hestia \
    --to=mailing-lists@xs4all.nl \
    --cc=linux-c-programming@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).