win32 get real implemented (timings that is).
[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.2 2007-01-05 12:40:05 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 #ifdef WIN32
15 #include <windows.h>
16 #endif
17
18 static void tst(void)
19 {
20     yaz_timing_t t = yaz_timing_create();
21     double real, user, sys;
22     int i = 0;
23
24     YAZ_CHECK(t);
25     if (!t)
26         return;
27
28 #ifdef WIN32
29     Sleep(100);
30 #endif
31     for (i = 0; i<100000; i++)
32         ;
33
34     YAZ_CHECK_EQ(i, 100000);
35
36     yaz_timing_stop(t);
37
38     real = yaz_timing_get_real(t);
39     YAZ_CHECK(real == -1.0 || real >= 0.0);
40
41     user = yaz_timing_get_user(t);
42     YAZ_CHECK(user == -1.0 || user >= 0.0);
43
44     sys = yaz_timing_get_sys(t); 
45     YAZ_CHECK(sys == -1.0 || sys >= 0.0);
46
47     yaz_log(YLOG_LOG, "real=%f user=%f sys=%f", real, user, sys);
48    
49     yaz_timing_destroy(&t);
50     YAZ_CHECK(!t);
51 }
52
53
54 int main (int argc, char **argv)
55 {
56     YAZ_CHECK_INIT(argc, argv);
57     YAZ_CHECK_LOG();
58     tst();
59     YAZ_CHECK_TERM;
60 }
61
62 /*
63  * Local variables:
64  * c-basic-offset: 4
65  * indent-tabs-mode: nil
66  * End:
67  * vim: shiftwidth=4 tabstop=8 expandtab
68  */
69