Changeset 205f1add in mainline for uspace/app/bnchmark/bnchmark.c


Ignore:
Timestamp:
2018-08-23T21:14:56Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Children:
f33c989e
Parents:
e2625b1a
git-author:
Jakub Jermar <jakub@…> (2018-08-21 21:58:52)
git-committer:
Jakub Jermar <jakub@…> (2018-08-23 21:14:56)
Message:

Get rid of sys/time.h

This commit moves the POSIX-like time functionality from libc's
sys/time.h to libposix and introduces C99-like or HelenOS-specific
interfaces to libc.

Specifically, use of sys/time.h, struct timeval, suseconds_t and
gettimeofday is replaced by time.h (C99), struct timespec (C99),
usec_t (HelenOS) and getuptime / getrealtime (HelenOS).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bnchmark/bnchmark.c

    re2625b1a r205f1add  
    5656
    5757typedef errno_t (*measure_func_t)(void *);
    58 typedef unsigned long umseconds_t; /* milliseconds */
    5958
    6059static void syntax_print(void);
    6160
    62 static errno_t measure(measure_func_t fn, void *data, umseconds_t *result)
    63 {
    64         struct timeval start_time;
    65         gettimeofday(&start_time, NULL);
     61static errno_t measure(measure_func_t fn, void *data, msec_t *result)
     62{
     63        struct timespec start_time;
     64        getuptime(&start_time);
    6665
    6766        errno_t rc = fn(data);
     
    7170        }
    7271
    73         struct timeval final_time;
    74         gettimeofday(&final_time, NULL);
     72        struct timespec final_time;
     73        getuptime(&final_time);
    7574
    7675        /* Calculate time difference in milliseconds */
    77         *result = ((final_time.tv_usec - start_time.tv_usec) / 1000) +
    78             ((final_time.tv_sec - start_time.tv_sec) * 1000);
     76        *result = NSEC2USEC(ts_sub_diff(&final_time, &start_time));
    7977        return EOK;
    8078}
     
    133131{
    134132        errno_t rc;
    135         umseconds_t milliseconds_taken = 0;
     133        msec_t milliseconds_taken = 0;
    136134        char *path = NULL;
    137135        measure_func_t fn = NULL;
     
    194192                }
    195193
    196                 printf("%s;%s;%s;%lu;ms\n", test_type, path, log_str, milliseconds_taken);
     194                printf("%s;%s;%s;%lld;ms\n", test_type, path, log_str, milliseconds_taken);
    197195        }
    198196
Note: See TracChangeset for help on using the changeset viewer.