[3.1.4, Windows 7, MinGW 8.1.0] Some questions about wxStopWatch

13 views
Skip to first unread message

Parduz

unread,
Apr 7, 2021, 4:06:50 AM4/7/21
to wx-u...@googlegroups.com
Hello, i asked these questions in the wxWidgets forum and they suggested to write here, so here i am.

1) How can i know if a wxStopWatch is paused or running? I can't find any method.
2) Why m_elapsedBeforePause and m_pauseCount are all private with no methods to access them)?
3) Same question about GetClockFreq and GetCurrentClockValue?

If they were at least protected i could use them in a derived class, but as they are i can't really access anything.
There a reasoning beyond this that i don't catch?
If not, may i suggest to make methods and variables less "private"?

Thanks

Vadim Zeitlin

unread,
Apr 7, 2021, 6:32:21 AM4/7/21
to wx-u...@googlegroups.com
On Wed, 7 Apr 2021 08:06:42 +0000 (UTC) 'Parduz' via wx-users wrote:

P> Hello, i asked these questions in the wxWidgets forum and they suggested
P> to write here, so here i am.
P>
P> 1) How can i know if a wxStopWatch is paused or running? I can't find
P> any method.
P> 2) Why m_elapsedBeforePause and m_pauseCount are all private with no
P> methods to access them)?
P> 3) Same question about GetClockFreq and GetCurrentClockValue?

The answer to all these questions is that wxStopWatch provides a
deliberately simple interface for the one simple thing that it does. The
only thing that I could consider adding would be IsPaused() but it's really
surprising that you need it because in typical use you do something like

void foo()
{
wxStopWatch sw;
... code you benchmark ...

sw.Pause();
... code you don't want to include in benchmark ...
sw.Resume();

... more code you benchmark ...

wxLogInfo("Benchmark took %ldms", sw.Time());
}

i.e. you know whether it's paused or not just from the structure of your
code.

If you use it for something more complicated than this, you probably
shouldn't, especially nowadays when you have C++11 chrono.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Reply all
Reply to author
Forward
0 new messages