dummzeuch 1505 Posted May 30, 2020 I must be doing something wrong here: var Stopwatch: TStopwatch; begin Stopwatch.Start; sleep(3000); Stopwatch.Stop; m_Result.Lines.Add(format('Took %.3f seconds', [Stopwatch.Elapsed.TotalSeconds])); end; The result is "-130847749795,796 seconds", I was, of course, expecting something around 3. What am I missing? Share this post Link to post
dummzeuch 1505 Posted May 30, 2020 (edited) Ouch! Forget it: I didn't reset the stopwatch first: var Stopwatch: TStopwatch; begin Stopwatch.Reset; //<<<--- this was missing Stopwatch.Start; sleep(3000); Stopwatch.Stop; m_Result.Lines.Add(format('Took %.3f seconds', [Stopwatch.Elapsed.TotalSeconds])); end; Edited May 30, 2020 by dummzeuch Share this post Link to post
MarkShark 27 Posted May 30, 2020 I always do Stopwatch := TStopwatch.StartNew; On a side note I wonder if the new managed records thing could make your original one work (which I would prefer.) 3 Share this post Link to post
dummzeuch 1505 Posted May 30, 2020 18 minutes ago, MarkShark said: On a side note I wonder if the new managed records thing could make your original one work (which I would prefer.) Yes, I'm sure it could. Share this post Link to post
Leif Uneus 43 Posted May 30, 2020 Use StopWatch := TStopWatch.Create to initialize a new TStopWatch value in a stopped condition or StopWatch := TStopWatch.StartNew to return a started stopwatch. See http://docwiki.embarcadero.com/Libraries/Rio/en/System.Diagnostics.TStopwatch.Create Share this post Link to post
David Heffernan 2345 Posted May 30, 2020 4 hours ago, Leif Uneus said: StopWatch := TStopWatch.StartNew is all you need 1 Share this post Link to post
Anders Melander 1782 Posted May 30, 2020 24 minutes ago, David Heffernan said: is all you need I would think RTFM is all he needs: Quote TStopwatch is not a class but still requires explicit initialization. Call the StartNew or Create method to initialize a TStopwatch value. Share this post Link to post
dummzeuch 1505 Posted May 31, 2020 What i don't need are snide remarks like this. 7 Share this post Link to post
David Heffernan 2345 Posted May 31, 2020 I don't think RTFM is the right way to say it. But I trust you make a mental note to check the documentation another time. I mean, the way the message was delivered was clumsy, but the thrust of the message is valid. 2 Share this post Link to post
dummzeuch 1505 Posted May 31, 2020 One of the bad habits I have picked up over the years is not looking into the documentation. The only reason I can give is that the documentation was so bad for some time that the time it took usually was wasted. Since documentation has become much better (but is still far from perfect, especially some of the examples), this no longer applies though. Share this post Link to post
David Heffernan 2345 Posted May 31, 2020 1 hour ago, dummzeuch said: One of the bad habits I have picked up over the years is not looking into the documentation. The only reason I can give is that the documentation was so bad for some time that the time it took usually was wasted. Since documentation has become much better (but is still far from perfect, especially some of the examples), this no longer applies though. I think it is often the case that documentation for Delphi is added sometime after the code is released. Documentation for mature parts of the libs is often reasonable. Not so much for newly released libs. I think this is a really poor way to develop libs though. I routinely find design issues when I am writing documentation. If you write the documentation after you release then you'll find those issues after the consumers have started using the libs. Share this post Link to post
Mark- 29 Posted May 31, 2020 37 minutes ago, David Heffernan said: I routinely find design issues when I am writing documentation. Same here plus, I can verify all the design and functionality goals are achieved. In some cases I write the documentation before the code. Especially when the goal is stated in one line but contains many facets. Share this post Link to post