2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: timing.c,v 1.2 2007-01-05 11:44:49 adam Exp $
10 * \brief Timing Utilities
20 #include <sys/times.h>
27 #include <yaz/xmalloc.h>
28 #include <yaz/timing.h>
32 struct tms tms1, tms2;
35 struct timeval start_time, end_time;
37 double real_sec, user_sec, sys_sec;
40 yaz_timing_t yaz_timing_create(void)
42 yaz_timing_t t = xmalloc(sizeof(*t));
47 void yaz_timing_start(yaz_timing_t t)
58 gettimeofday(&t->start_time, 0);
65 void yaz_timing_stop(yaz_timing_t t)
70 t->user_sec = (double) (t->tms2.tms_utime - t->tms1.tms_utime)/100;
71 t->sys_sec = (double) (t->tms2.tms_stime - t->tms1.tms_stime)/100;
74 gettimeofday(&t->end_time, 0);
75 t->real_sec = ((t->end_time.tv_sec - t->start_time.tv_sec) * 1000000.0 +
76 t->end_time.tv_usec - t->start_time.tv_usec) / 1000000;
81 double yaz_timing_get_real(yaz_timing_t t)
86 double yaz_timing_get_user(yaz_timing_t t)
91 double yaz_timing_get_sys(yaz_timing_t t)
96 void yaz_timing_destroy(yaz_timing_t *tp)
108 * indent-tabs-mode: nil
110 * vim: shiftwidth=4 tabstop=8 expandtab