edbca1d257624ef975026c34d863d2ff6e43a828
[yaz-moved-to-github.git] / test / test_timing.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2010 Index Data
3  * See the file LICENSE for details.
4  */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8
9 #include <yaz/timing.h>
10 #include <yaz/test.h>
11 #include <yaz/log.h>
12 #ifdef WIN32
13 #include <windows.h>
14 #endif
15
16 static void tst(void)
17 {
18     yaz_timing_t t = yaz_timing_create();
19     double real, user, sys;
20     int i = 0;
21     double x = 0;
22
23     YAZ_CHECK(t);
24     if (!t)
25         return;
26
27 #ifdef WIN32
28     Sleep(10);
29 #endif
30     for (i = 0; i<5000000; i++)
31         x += i;
32
33     YAZ_CHECK_EQ(i, 5000000);
34
35     yaz_log(YLOG_LOG, "i=%d x=%f", i, x);
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  * c-file-style: "Stroustrup"
66  * indent-tabs-mode: nil
67  * End:
68  * vim: shiftwidth=4 tabstop=8 expandtab
69  */
70