MFEM  v4.6.0
Finite element discretization library
tic_toc.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_TIC_TOC
13 #define MFEM_TIC_TOC
14 
15 #include "../config/config.hpp"
16 #include <memory>
17 
18 #ifndef MFEM_TIMER_TYPE
19 #ifndef _WIN32
20 #define MFEM_TIMER_TYPE 0
21 #else
22 #define MFEM_TIMER_TYPE 3
23 #endif
24 #endif
25 
26 namespace mfem
27 {
28 
29 namespace internal
30 {
31 class StopWatch;
32 }
33 
34 /// Timing object
35 class StopWatch
36 {
37 private:
38  std::unique_ptr<internal::StopWatch> M; ///< Pointer to implementation.
39 
40 public:
41  /// Creates a new (stopped) StopWatch object.
42  StopWatch();
43 
44  /// Clear the elapsed time on the stopwatch and restart it if it's running.
45  void Clear();
46 
47  /// Start the stopwatch. The elapsed time is @b not cleared.
48  void Start();
49 
50  /// Stop the stopwatch.
51  void Stop();
52 
53  /// @brief Clears and restarts the stopwatch. Equivalent to Clear() followed by
54  /// Start().
55  void Restart();
56 
57  /// Return the time resolution available to the stopwatch.
58  double Resolution();
59 
60  /// @brief Return the number of real seconds elapsed since the stopwatch was
61  /// started.
62  double RealTime();
63 
64  /// @brief Return the number of user seconds elapsed since the stopwatch was
65  /// started.
66  double UserTime();
67 
68  /// @brief Return the number of system seconds elapsed since the stopwatch
69  /// was started.
70  double SystTime();
71 
72  /// Default destructor.
73  ~StopWatch();
74 };
75 
76 
77 extern MFEM_EXPORT StopWatch tic_toc;
78 
79 /// Start the tic_toc timer
80 extern void tic();
81 
82 /// End timing and return the time from tic() to toc() in seconds.
83 extern double toc();
84 
85 }
86 
87 #endif
~StopWatch()
Default destructor.
StopWatch tic_toc
Definition: tic_toc.cpp:447
double RealTime()
Return the number of real seconds elapsed since the stopwatch was started.
Definition: tic_toc.cpp:429
void Restart()
Clears and restarts the stopwatch. Equivalent to Clear() followed by Start().
Definition: tic_toc.cpp:413
void Stop()
Stop the stopwatch.
Definition: tic_toc.cpp:419
double UserTime()
Return the number of user seconds elapsed since the stopwatch was started.
Definition: tic_toc.cpp:434
Timing object.
Definition: tic_toc.hpp:35
double Resolution()
Return the time resolution available to the stopwatch.
Definition: tic_toc.cpp:424
void Start()
Start the stopwatch. The elapsed time is not cleared.
Definition: tic_toc.cpp:408
StopWatch()
Creates a new (stopped) StopWatch object.
Definition: tic_toc.cpp:401
void tic()
Start the tic_toc timer.
Definition: tic_toc.cpp:449
double toc()
End timing and return the time from tic() to toc() in seconds.
Definition: tic_toc.cpp:455
void Clear()
Clear the elapsed time on the stopwatch and restart it if it&#39;s running.
Definition: tic_toc.cpp:403
double SystTime()
Return the number of system seconds elapsed since the stopwatch was started.
Definition: tic_toc.cpp:439