File: clock.cpp

package info (click to toggle)
synfigstudio 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 162,048 kB
  • sloc: cpp: 208,474; javascript: 25,487; ansic: 13,216; python: 7,509; sh: 6,391; makefile: 2,999; objc: 1,400; csh: 486; perl: 238; ruby: 73; xml: 11
file content (78 lines) | stat: -rw-r--r-- 2,343 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*! ========================================================================
** Extended Template and Library Test Suite
** Clock Test
** $Id$
**
** Copyright (c) 2002 Robert B. Quattlebaum Jr.
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** General Public License for more details.
**
** === N O T E S ===========================================================
**
** ========================================================================= */

/* === H E A D E R S ======================================================= */

#include <ETL/clock>
#include <stdio.h>
#include <chrono>
#include <thread>

/* === M A C R O S ========================================================= */

using namespace etl;

/* === C L A S S E S ======================================================= */


/* === P R O C E D U R E S ================================================= */

int basic_test(void)
{
	int ret=0;

	etl::clock timer;
	float amount, total;

	for(amount=3.0;amount>=0.00015;amount/=2.0)
	{
		if(amount*1000000.0<1000.0f)
			fprintf(stderr,"waiting %f microseconds...\n",amount*1000000.0);
		else if(amount*1000.0<400.0f)
			fprintf(stderr,"waiting %f milliseconds...\n",amount*1000.0);
		else
			fprintf(stderr,"waiting %f seconds...\n",amount);

		timer.reset();
		std::this_thread::sleep_for(std::chrono::microseconds ((std::int64_t)(amount*1000000.f)));
		total=timer();
		if((total-amount)*1000000.0<1000.0f)
			fprintf(stderr," ** I waited %f seconds, error of %f microseconds\n",total,(total-amount)*1000000);
		else if((total-amount)*1000.0<400.0f)
			fprintf(stderr," ** I waited %f seconds, error of %f milliseconds\n",total,(total-amount)*1000);
		else
			fprintf(stderr," ** I waited %f seconds, error of %f seconds\n",total,total-amount);

	}
	return ret;
}

/* === E N T R Y P O I N T ================================================= */

int main()
{
	int error=0;

	error+=basic_test();

	return error;
}