blob: 74b3fb04e08c872fa9db0e9fca05427c2a810498 (
plain) (
blame)
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
|
// Copyright 2011-2022, Molecular Matters GmbH <[email protected]>
// See LICENSE.txt for licensing details (2-clause BSD License: https://opensource.org/licenses/BSD-2-Clause)
#include "Examples_PCH.h"
#include "ExampleTimedScope.h"
namespace
{
static unsigned int g_indent = 0u;
static void PrintIndent(void)
{
printf("%.*s", g_indent * 2u, "| | | | | | | | ");
}
}
TimedScope::TimedScope(const char* message)
: m_begin(std::chrono::high_resolution_clock::now())
{
PrintIndent();
++g_indent;
printf("%s\n", message);
}
void TimedScope::Done(void) const
{
--g_indent;
PrintIndent();
const double milliSeconds = ReadMilliseconds();
printf("---> done in %.3fms\n", milliSeconds);
}
void TimedScope::Done(size_t count) const
{
--g_indent;
PrintIndent();
const double milliSeconds = ReadMilliseconds();
printf("---> done in %.3fms (%zu elements)\n", milliSeconds, count);
}
double TimedScope::ReadMilliseconds(void) const
{
const std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double> seconds = now - m_begin;
return seconds.count() * 1000.0;
}
|