Jump to content
Sign in to follow this  
dummzeuch

TStopwatch.Elapsed

Recommended Posts

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
Posted (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 by dummzeuch

Share this post


Link to post

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.)

  • Like 2

Share this post


Link to post
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

What i don't need are snide remarks like this.

  • Like 7

Share this post


Link to post

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.

 

 

  • Like 2

Share this post


Link to post

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×