Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
onitor/TimeMonitor_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "Teuchos_TimeMonitor.hpp"
12 
13 
14 namespace {
15 
16 
17 int someFunction()
18 {
19  TEUCHOS_FUNC_TIME_MONITOR("someFunction1");
20  TEUCHOS_FUNC_TIME_MONITOR_DIFF("someFunction2", diff);
21  return 5;
22 }
23 
24 
25 TEUCHOS_UNIT_TEST( TimeMonitor, someFunction_timed )
26 {
27  const int rtn = someFunction();
28  TEST_EQUALITY(rtn, 5);
29 }
30 
31 TEUCHOS_UNIT_TEST( TimeMonitor, formatting)
32 {
33  using namespace Teuchos;
34 
35  // Zero out previous timers
37 
38  std::ostringstream out1, out2;
39  const std::string filter = "";
40 
41  // Check std::fixed formatting
42  out1 << std::fixed;
43  TimeMonitor::report(out1, filter);
44  bool test1 = (out1.str().find("someFunction1 0.0000 (0)") != std::string::npos);
45  TEST_EQUALITY(test1, true);
46 
47  // Check std::scientific formatting
48  out2 << std::scientific;
49  TimeMonitor::report(out2, filter);
50  bool test2 = (out2.str().find("someFunction1 0.0000e+00 (0)") != std::string::npos);
51  TEST_EQUALITY(test2, true);
52 }
53 
54 
55 } // namespace
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
Defines a timer for a specific function.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Unit testing support.
Scope guard for Teuchos::Time, with MPI collective timer reporting.
static void zeroOutTimers()
Reset all global timers to zero.
static void report(Ptr< const Comm< int > > comm, std::ostream &out, const std::string &filter, const RCP< ParameterList > &params=null)
Report timer statistics to the given output stream.
#define TEUCHOS_FUNC_TIME_MONITOR_DIFF(FUNCNAME, DIFF)
Defines a timer for a specific function (with differentiator).