1 /* $Id: timing.c,v 1.1 2006-12-11 09:50:36 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <sys/times.h>
32 #include <yaz/xmalloc.h>
33 #include <idzebra/util.h>
36 struct tms tms1, tms2;
37 struct timeval start_time, end_time;
38 double real_sec, user_sec, sys_sec;
41 zebra_timing_t zebra_timing_create(void)
43 zebra_timing_t t = xmalloc(sizeof(*t));
44 zebra_timing_start(t);
48 void zebra_timing_start(zebra_timing_t t)
53 gettimeofday(&t->start_time, 0);
61 void zebra_timing_stop(zebra_timing_t t)
68 gettimeofday(&t->end_time, 0);
71 t->real_sec = ((t->end_time.tv_sec - t->start_time.tv_sec) * 1000000.0 +
72 t->end_time.tv_usec - t->start_time.tv_usec) / 1000000;
74 t->user_sec = (double) (t->tms2.tms_utime - t->tms1.tms_utime)/100;
75 t->sys_sec = (double) (t->tms2.tms_stime - t->tms1.tms_stime)/100;
80 double zebra_timing_get_real(zebra_timing_t t)
85 double zebra_timing_get_user(zebra_timing_t t)
90 double zebra_timing_get_sys(zebra_timing_t t)
95 void zebra_timing_destroy(zebra_timing_t *tp)
107 * indent-tabs-mode: nil
109 * vim: shiftwidth=4 tabstop=8 expandtab