Y
Y
Yam0lod5y2020-11-10 23:02:08
Delphi
Yam0lod5y, 2020-11-10 23:02:08

Success counter per minute in Delphi?

I'm trying to make a counter of operations per minute, I'm already tired, I found this code in c ++, how can I transfer it to delphi?

var temp = 0;
for (int i = FailedList.Count() - 1; i >= 0; i--) { if ((DateTime.Now - FailedList[i].Time).TotalSeconds > 60) break; temp++; }
cpm = temp;


here is an example of my code where I think, but I don’t have enough brains to think it out, there was an option, but it swears at 0, although everything works in another environment, there is a problem with the remainder, for some reason, when dividing, it gives out only 0, without hundredths, etc. and there is a completely unpleasant moment that it shows the result only after a minute
CPM := CHECKEDCount div ((DATENOWunix - STARTTIMEunix) div 60000);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
Hemul GM, 2020-11-11
@Yam0lod5y

Use tiki. GetTickCount is the OS counter.

var Save := GetTickCount;
<do something>
var Delta := GetTickCount - Save; <- Тут кол-во миллисекунд, потраченное на действие выше

O
OCTAGRAM, 2020-11-11
@OCTAGRAM

Usually unix calendar is measured in seconds, and only in JS exception with milliseconds. If it's true milliseconds, maybe then replace the div's integer division with a floating point operation /
It's also a good practice to use non-civil calendar if possible, but monotonic time. In the Ada language, this is an appendix to the D.8 Monotonic Time standard that describes the Ada.Real_Time package . In Delphi, the same functionality is hidden in a module with the obscure name System.Diagnostics . This is if the program does not restart during the entire interval of interest.

A
acwartz, 2020-11-11
@acwartz

Well, why do you need Unixtime for this?
There is also the OS function GetTickCount , and if you work with dates, then DateUtils has MillisecondsBetween which will return exactly the same result as GetTickCount. Further, even in seconds, even in hours ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question