Moved ignore files.
[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.3 2007-01-05 14:05:55 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     double x = 0;
24
25     YAZ_CHECK(t);
26     if (!t)
27         return;
28
29 #ifdef WIN32
30     Sleep(10);
31 #endif
32     for (i = 0; i<5000000; i++)
33         x += i;
34
35     YAZ_CHECK_EQ(i, 5000000);
36
37     yaz_log(YLOG_LOG, "i=%d x=%f", i, x);
38     yaz_timing_stop(t);
39
40     real = yaz_timing_get_real(t);
41     YAZ_CHECK(real == -1.0 || real >= 0.0);
42
43     user = yaz_timing_get_user(t);
44     YAZ_CHECK(user == -1.0 || user >= 0.0);
45
46     sys = yaz_timing_get_sys(t); 
47     YAZ_CHECK(sys == -1.0 || sys >= 0.0);
48
49     yaz_log(YLOG_LOG, "real=%f user=%f sys=%f", real, user, sys);
50    
51     yaz_timing_destroy(&t);
52     YAZ_CHECK(!t);
53 }
54
55
56 int main (int argc, char **argv)
57 {
58     YAZ_CHECK_INIT(argc, argv);
59     YAZ_CHECK_LOG();
60     tst();
61     YAZ_CHECK_TERM;
62 }
63
64 /*
65  * Local variables:
66  * c-basic-offset: 4
67  * indent-tabs-mode: nil
68  * End:
69  * vim: shiftwidth=4 tabstop=8 expandtab
70  */
71