1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 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;
44 double real_sec, user_sec, sys_sec;
47 yaz_timing_t yaz_timing_create(void)
49 yaz_timing_t t = (yaz_timing_t) xmalloc(sizeof(*t));
55 static void get_process_time(ULONGLONG *lp_user, ULONGLONG *lp_sys)
57 FILETIME create_t, exit_t, sys_t, user_t;
60 GetProcessTimes(GetCurrentProcess(), &create_t, &exit_t, &sys_t, &user_t);
61 li.LowPart = user_t.dwLowDateTime;
62 li.HighPart = user_t.dwHighDateTime;
63 *lp_user = li.QuadPart;
65 li.LowPart = sys_t.dwLowDateTime;
66 li.HighPart = sys_t.dwHighDateTime;
67 *lp_sys = li.QuadPart;
69 static void get_date_as_largeinteger(LONGLONG *lp)
73 GetSystemTimeAsFileTime(&f);
74 li.LowPart = f.dwLowDateTime;
75 li.HighPart = f.dwHighDateTime;
81 void yaz_timing_start(yaz_timing_t t)
93 gettimeofday(&t->start_time, 0);
100 get_date_as_largeinteger(&t->start_time);
101 get_process_time(&t->start_time_user, &t->start_time_sys);
106 void yaz_timing_stop(yaz_timing_t t)
111 t->user_sec = (double) (t->tms2.tms_utime - t->tms1.tms_utime)/100;
112 t->sys_sec = (double) (t->tms2.tms_stime - t->tms1.tms_stime)/100;
115 gettimeofday(&t->end_time, 0);
116 t->real_sec = ((t->end_time.tv_sec - t->start_time.tv_sec) * 1000000.0 +
117 t->end_time.tv_usec - t->start_time.tv_usec) / 1000000;
120 get_date_as_largeinteger(&t->end_time);
121 t->real_sec = (t->end_time - t->start_time) / 10000000.0;
123 get_process_time(&t->end_time_user, &t->end_time_sys);
124 t->user_sec = (t->end_time_user - t->start_time_user) / 10000000.0;
125 t->sys_sec = (t->end_time_sys - t->start_time_sys) / 10000000.0;
130 double yaz_timing_get_real(yaz_timing_t t)
135 double yaz_timing_get_user(yaz_timing_t t)
140 double yaz_timing_get_sys(yaz_timing_t t)
145 void yaz_timing_destroy(yaz_timing_t *tp)
157 * c-file-style: "Stroustrup"
158 * indent-tabs-mode: nil
160 * vim: shiftwidth=4 tabstop=8 expandtab