Measurement of time. Different results. decided lazarus / 21-General ---------------------------------------------------------------------- Seenkao · 2021-03-13 20:18 Hello! In general, the essence is as follows. I request time, I launch the code in the cycle, on the output from the cycle again requesting the time and look at the delta. Each time the same code, with the same number of cycles, issues a different amount of time spent. What does it depend on? How can I more accurately calculate the time interval? Sorry for my English. ---------------------------------------------------------------------- 440bx · 2021-03-13 20:35 Quote from: Seenkao on March 13, 2021, 09:18:38 pmWhat does it depend on? How can I more accurately calculate the time interval? Sounds like your program is running under a multitasking O/S.  In that case, your program is subject to the whims of the O/S scheduler which pretty much guarantees that each time measurement is going to vary. As far as accuracy, about the only thing you can do is repeat the measurement about 20 to 30 times.  Throw away any "outlier" measurements then take the average of the remaining ones.  That won't give you a "CPU accurate" measurement but, it will give you an "O/S accurate" average measurement. HTH. ---------------------------------------------------------------------- marcov · 2021-03-13 20:44 Moreover, modern processors don't run on fixed frequencies, but can vary due to e.g. turboboost ---------------------------------------------------------------------- Seenkao · 2021-03-13 21:07 Quote from: 440bx on March 13, 2021, 09:35:21 pm As far as accuracy, about the only thing you can do is repeat the measurement about 20 to 30 times.  Throw away any "outlier" measurements then take the average of the remaining ones.  That won't give you a "CPU accurate" measurement but, it will give you an "O/S accurate" average measurement For this I used cycles. up to 10,000. The problem is not in what gives a different delta. The problem is that the difference goes with different launches of the program. All measured delta is increasing and decreasing depending on when we run the program. ---------------------------------------------------------------------- Seenkao · 2021-03-13 21:29 That was my fault. I used a renderer in a loop. And you need to use "clean" code. External calls interfere with validation. ---------------------------------------------------------------------- lucamar · 2021-03-13 22:49 Quote from: Seenkao on March 13, 2021, 10:07:57 pmThe problem is that the difference goes with different launches of the program. All measured delta is increasing and decreasing depending on when we run the program. That's to be expected in multitasking OSs. Any run-time measure will depend on several factors, most of them out of your control, which fall in what is generically know as "system load". Imagine if, for example, you run your program while the system is trying to ascertain if there is any update on the web, or when it's updating its swap space, or doing any other "under-the-hood" task. The results will be quite different than if the system were idle, just waiting for a program to run. That's why configuring, say, a server so it spends a maximum of its time "serving" is considered an almost arcane science. ---------------------------------------------------------------------- winni · 2021-03-13 23:57 Hi! You did not tell us your OS but anyway: There are a lot of jobs which depend on especial time stamps. For example: At  hh:mm:ss is the backup started - by cron. Or the latest security patches are downloaded. There are jobs which depend on other situations: If the logfile of service xyz ist greater than nn Megabyte the lograte is started which compresses a part of the logfile history. In hot regions or in summertime: If the temperature of the CPU exceeds trigger nn degrees centigrade the max frequency of the CPU is restricted. Or you have enabled the automatic update of Windows, which just started. Or, or, or... If you want constant values in your app,  you have to use a real time OS. No way out. Winni