Stable Tag: Removing old tag
[synfig.git] / ETL / tags / 0.61.06 / test / clock.cpp
1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
3 ** Clock Test
4 ** $Id$
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 **
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
12 **
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 ** General Public License for more details.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #include <ETL/clock>
25 #include <stdio.h>
26
27 /* === M A C R O S ========================================================= */
28
29 using namespace etl;
30
31 /* === C L A S S E S ======================================================= */
32
33
34 /* === P R O C E D U R E S ================================================= */
35
36 int basic_test(void)
37 {
38         int ret=0;
39         fprintf(stderr,"default etl::clock precision:  %0.8f\n",etl::clock::precision());
40         fprintf(stderr,"realtime etl::clock precision: %0.8f\n",etl::clock_realtime::precision());
41         fprintf(stderr,"proctime etl::clock precision: %0.8f\n",etl::clock_proctime::precision());
42
43         etl::clock_realtime timer;
44         etl::clock::value_type amount,total;
45
46         for(amount=3.0;amount>=0.00015;amount/=2.0)
47         {
48                 if(amount*1000000.0<1000.0f)
49                         fprintf(stderr,"waiting %f microseconds...\n",amount*1000000.0);
50                 else if(amount*1000.0<400.0f)
51                         fprintf(stderr,"waiting %f milliseconds...\n",amount*1000.0);
52                 else
53                         fprintf(stderr,"waiting %f seconds...\n",amount);
54
55                 timer.reset();
56                 etl::clock::sleep(amount);
57                 total=timer();
58                 if((total-amount)*1000000.0<1000.0f)
59                         fprintf(stderr," ** I waited %f seconds, error of %f microseconds\n",total,(total-amount)*1000000);
60                 else if((total-amount)*1000.0<400.0f)
61                         fprintf(stderr," ** I waited %f seconds, error of %f milliseconds\n",total,(total-amount)*1000);
62                 else
63                         fprintf(stderr," ** I waited %f seconds, error of %f seconds\n",total,total-amount);
64
65         }
66         return ret;
67 }
68
69 /* === E N T R Y P O I N T ================================================= */
70
71 int main()
72 {
73         int error=0;
74
75         error+=basic_test();
76
77         return error;
78 }
79