How does clock_ms() work?

Hello. While waiting for PLCs to arrive I have been experimenting with ARsim and noticed that clock_ms() always returns the same number if called within the same cycle of a program. For example:
x = clock_ms();

DoSomething();

y = clock_ms();
The values of x and y always match within a cycle even if DoSomething() takes seconds to execute. Is this an expected behavior or a limitation of the simulator?

Hi @Alex_Kolesen

I never used clock_ms() function, did you try the same thing with RTC_gettime() function?

Regards,
Florent

or AsIOTimeStamp()

I asked AI help, and I see it elaborated more or less all topic we have on the community regarding timing and arsim:

ARsim runs as a non-real-time application on top of the Windows operating system. While a physical PLC uses a highly accurate hardware clock, ARsim timing is reliant on Windows thread scheduling.

The Result: The actual time elapsed between cyclic tasks may experience significant jitter or drift. If you use clock_ms() to measure exact physical execution times (like sub-millisecond task durations), your measurements will reflect Windows performance rather than true PLC capability.

=====
How to deal with clock_ms() counting longer than 24days? - Ask Questions / Programming - B&R Community

Ciao
Valerio

@florent.boissadier , thank you for your suggestions. RTC_gettime() seems to be doing the same thing and returns the same value within a cycle in ARsim (the value updates only on the next iteration of the cyclic). AsIOTimeStamp() on the other hand works as expected and returns two distinct values even if called twice within the same cycle. Thank you for your help.