This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
stopwatch.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_STOPWATCH_H
8#define PXR_BASE_TF_STOPWATCH_H
9
12
13#include "pxr/pxr.h"
14
16#include "pxr/base/tf/api.h"
17
18#include <iosfwd>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
39{
40public:
41
48 inline void Start() {
49 _startTick = ArchGetStartTickTime();
50 }
51
62 inline void Stop() {
63 _nTicks += ArchGetStopTickTime() - _startTick;
64 _sampleCount++;
65 }
66
68 void Reset() {
69 _nTicks = 0;
70 _sampleCount = 0;
71 }
72
80 void AddFrom(const TfStopwatch& t) {
81 _nTicks += t._nTicks;
82 _sampleCount += t._sampleCount;
83 }
84
90 int64_t GetNanoseconds() const {
91 return ArchTicksToNanoseconds(_nTicks);
92 }
93
98 int64_t GetMicroseconds() const {
99 return GetNanoseconds() / 1000;
100 }
101
103 int64_t GetMilliseconds() const {
104 return GetMicroseconds() / 1000;
105 }
106
112 size_t GetSampleCount() const {
113 return _sampleCount;
114 }
115
117 double GetSeconds() const {
118 return ArchTicksToSeconds(_nTicks);
119 }
120
121private:
122 uint64_t _nTicks = 0;
123 uint64_t _startTick = 0;
124 size_t _sampleCount = 0;
125};
126
133TF_API std::ostream& operator<<(std::ostream& out, const TfStopwatch& s);
134
135PXR_NAMESPACE_CLOSE_SCOPE
136
137#endif // PXR_BASE_TF_STOPWATCH_H
Low-cost, high-resolution timer datatype.
Definition: stopwatch.h:39
void Start()
Record the current time for use by the next Stop() call.
Definition: stopwatch.h:48
void Stop()
Increases the accumulated time stored in the TfStopwatch.
Definition: stopwatch.h:62
double GetSeconds() const
Return the accumulated time in seconds as a double.
Definition: stopwatch.h:117
void Reset()
Resets the accumulated time and the sample count to zero.
Definition: stopwatch.h:68
int64_t GetNanoseconds() const
Return the accumulated time in nanoseconds.
Definition: stopwatch.h:90
int64_t GetMilliseconds() const
Return the accumulated time in milliseconds.
Definition: stopwatch.h:103
void AddFrom(const TfStopwatch &t)
Adds the accumulated time and sample count from t into the TfStopwatch.
Definition: stopwatch.h:80
size_t GetSampleCount() const
Return the current sample count.
Definition: stopwatch.h:112
int64_t GetMicroseconds() const
Return the accumulated time in microseconds.
Definition: stopwatch.h:98
uint64_t ArchGetStartTickTime()
Get a "start" tick time for measuring an interval of time, followed by a later call to ArchGetStopTic...
Definition: timing.h:68
uint64_t ArchGetStopTickTime()
Get a "stop" tick time for measuring an interval of time.
Definition: timing.h:109
ARCH_API double ArchTicksToSeconds(uint64_t nTicks)
Convert a duration measured in "ticks", as returned by ArchGetTickTime(), to seconds.
ARCH_API int64_t ArchTicksToNanoseconds(uint64_t nTicks)
Convert a duration measured in "ticks", as returned by ArchGetTickTime(), to nanoseconds.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
High-resolution, low-cost timing routines.