1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
8 * \brief Timing Utilities
21 #include <sys/times.h>
28 #include <yaz/xmalloc.h>
29 #include <yaz/timing.h>
33 struct tms tms1, tms2;
36 struct timeval start_time, end_time;
39 LONGLONG start_time, end_time;
40 LONGLONG start_time_sys, start_time_user;
41 LONGLONG end_time_sys, end_time_user;
43 double real_sec, user_sec, sys_sec;
46 yaz_timing_t yaz_timing_create(void)
48 yaz_timing_t t = (yaz_timing_t) xmalloc(sizeof(*t));
54 static void get_process_time(ULONGLONG *lp_user, ULONGLONG *lp_sys)
56 FILETIME create_t, exit_t, sys_t, user_t;
59 GetProcessTimes(GetCurrentProcess(), &create_t, &exit_t, &sys_t, &user_t);
60 li.LowPart = user_t.dwLowDateTime;
61 li.HighPart = user_t.dwHighDateTime;
62 *lp_user = li.QuadPart;
64 li.LowPart = sys_t.dwLowDateTime;
65 li.HighPart = sys_t.dwHighDateTime;
66 *lp_sys = li.QuadPart;
68 static void get_date_as_largeinteger(LONGLONG *lp)
72 GetSystemTimeAsFileTime(&f);
73 li.LowPart = f.dwLowDateTime;
74 li.HighPart = f.dwHighDateTime;
80 void yaz_timing_start(yaz_timing_t t)
92 gettimeofday(&t->start_time, 0);
99 get_date_as_largeinteger(&t->start_time);
100 get_process_time(&t->start_time_user, &t->start_time_sys);
104 void yaz_timing_stop(yaz_timing_t t)
109 t->user_sec = (double) (t->tms2.tms_utime - t->tms1.tms_utime)/100;
110 t->sys_sec = (double) (t->tms2.tms_stime - t->tms1.tms_stime)/100;
113 gettimeofday(&t->end_time, 0);
114 t->real_sec = ((t->end_time.tv_sec - t->start_time.tv_sec) * 1000000.0 +
115 t->end_time.tv_usec - t->start_time.tv_usec) / 1000000;
119 get_date_as_largeinteger(&t->end_time);
120 t->real_sec = (t->end_time - t->start_time) / 10000000.0;
122 get_process_time(&t->end_time_user, &t->end_time_sys);
123 t->user_sec = (t->end_time_user - t->start_time_user) / 10000000.0;
124 t->sys_sec = (t->end_time_sys - t->start_time_sys) / 10000000.0;
128 double yaz_timing_get_real(yaz_timing_t t)
133 double yaz_timing_get_user(yaz_timing_t t)
138 double yaz_timing_get_sys(yaz_timing_t t)
143 void yaz_timing_destroy(yaz_timing_t *tp)
155 * indent-tabs-mode: nil
157 * vim: shiftwidth=4 tabstop=8 expandtab