Added test of timing_t.
[yaz-moved-to-github.git] / test / tst_timing.c
1 /*
2  * Copyright (C) 1995-2007, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: tst_timing.c,v 1.1 2007-01-05 11:45:11 adam Exp $
6  */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 #include <yaz/timing.h>
12 #include <yaz/test.h>
13 #include <yaz/log.h>
14
15 static void tst(void)
16 {
17     yaz_timing_t t = yaz_timing_create();
18     double real, user, sys;
19     int i = 0;
20
21     YAZ_CHECK(t);
22     if (!t)
23         return;
24
25     for (i = 0; i<100000; i++)
26         ;
27
28     YAZ_CHECK_EQ(i, 100000);
29
30     yaz_timing_stop(t);
31
32     real = yaz_timing_get_real(t);
33     YAZ_CHECK(real == -1.0 || real >= 0.0);
34
35     user = yaz_timing_get_user(t);
36     YAZ_CHECK(user == -1.0 || user >= 0.0);
37
38     sys = yaz_timing_get_sys(t); 
39     YAZ_CHECK(sys == -1.0 || sys >= 0.0);
40
41     yaz_log(YLOG_LOG, "real=%f user=%f sys=%f", real, user, sys);
42    
43     yaz_timing_destroy(&t);
44     YAZ_CHECK(!t);
45 }
46
47
48 int main (int argc, char **argv)
49 {
50     YAZ_CHECK_INIT(argc, argv);
51     YAZ_CHECK_LOG();
52     tst();
53     YAZ_CHECK_TERM;
54 }
55
56 /*
57  * Local variables:
58  * c-basic-offset: 4
59  * indent-tabs-mode: nil
60  * End:
61  * vim: shiftwidth=4 tabstop=8 expandtab
62  */
63