Re: [cc65] gettimeofday()

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2012-01-19 20:15:37
On Thu, Jan 19, 2012 at 07:04:58AM +0200, Karri Kaksonen wrote:
> On 01/18/2012 10:25 PM, Ullrich von Bassewitz wrote:
>
>     struct currenttime {
>         unsigned    sec;
>         unsigned    msec;
>     };
>
>     struct currenttime getcurrenttime (void);
>
>
>
> I like this approach.

We can also use

    unsigned long getticker (void);
    /* Return the number of milliseconds since some undefined point
     * in the past
     */

Not sure which one is better. The first one allows easier access to seconds
while the second one allows easier handling of times that includes fractions
of seconds. When I look at my own time measurements, they look like this:

    /* Read the clock */
    clock_t Ticks = clock();

    /* Execute some code */
    ...

    /* Calculate the time used */
    Ticks = clock() - Ticks;
    Sec = (unsigned) (Ticks / CLOCKS_PER_SEC);
    Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;

    /* Print the time used */
    printf ("Time used: %u.%03u seconds\n", Sec, Milli);

which would speak more for the second prototype than for the former.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Jan 19 20:15:44 2012

This archive was generated by hypermail 2.1.8 : 2012-01-19 20:15:47 CET