Jumbo patch: Incorporate extraArgs in memcached key YAZ-747
[yaz-moved-to-github.git] / test / test_timing.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 #if HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 #include <yaz/timing.h>
13 #include <yaz/test.h>
14 #include <yaz/log.h>
15 #ifdef WIN32
16 #include <windows.h>
17 #endif
18
19 static void tst(void)
20 {
21     yaz_timing_t t = yaz_timing_create();
22     double real, user, sys;
23     int i = 0;
24     double x = 0;
25
26     YAZ_CHECK(t);
27     if (!t)
28         return;
29
30 #ifdef WIN32
31     Sleep(10);
32 #endif
33     for (i = 0; i<5000000; i++)
34         x += i;
35
36     YAZ_CHECK_EQ(i, 5000000);
37
38     yaz_log(YLOG_LOG, "i=%d x=%f", i, x);
39     yaz_timing_stop(t);
40
41     real = yaz_timing_get_real(t);
42     YAZ_CHECK(real == -1.0 || real >= 0.0);
43
44     user = yaz_timing_get_user(t);
45     YAZ_CHECK(user == -1.0 || user >= 0.0);
46
47     sys = yaz_timing_get_sys(t);
48     YAZ_CHECK(sys == -1.0 || sys >= 0.0);
49
50     yaz_log(YLOG_LOG, "real=%f user=%f sys=%f", real, user, sys);
51
52     yaz_timing_destroy(&t);
53     YAZ_CHECK(!t);
54 }
55
56
57 int main (int argc, char **argv)
58 {
59     YAZ_CHECK_INIT(argc, argv);
60     YAZ_CHECK_LOG();
61     tst();
62     YAZ_CHECK_TERM;
63 }
64
65 /*
66  * Local variables:
67  * c-basic-offset: 4
68  * c-file-style: "Stroustrup"
69  * indent-tabs-mode: nil
70  * End:
71  * vim: shiftwidth=4 tabstop=8 expandtab
72  */
73