How to access time with milliseconds in a script?

Hello everyone,

I am currently using the following command to get system time with minutes and seconds from a script:
:local lTime [/system clock get time];

However, I would like to also access milliseconds information about the current time. For example, when I ping a host, I get the time in 49ms859us. This shows me that the OS is capable of displaying time information in ‘ms’ and even ‘us’ increments. How can I access time with milliseconds in a script?

Best,
Birkan

Useless data, RouterBOARDs do not have RTC and any load fluctuation affects the accuracy of the time.
Might as well put random milliseconds in there.

:put [:timestamp]
# 2859w6d10:50:42.236575187
:put [:tonsec [:timestamp]]
# 1729680660992477203

Timestamp is a “time” type since 1/1/1970 epoch. But [:tonsec] get you a “number”, with nanoseconds, from any “time” type.

To @rextended point… I guess it took 84760ns to figure out it should wait 0s :wink::

{ 
:local ts1 [:timestamp]
:delay 1ns
:local ts2 [:timestamp] 
:put ($ts1-$ts2) 
:put [:tonsec ($ts1-$ts2)]
}
# -00:00:00.000084760
# -84760
# Warning: value of delay-time was rounded down to 0s

Thank you for your replies. I used a small script to test various metrics. I found setting the delay as 0.x seconds to be better than x00ms. I would like to use this to benchmark various system calls and if necessarily add delays.

:local lTime [/system clock get time];
:local lTimestamp [:timestamp]
:delay 0.01s # 0.01s or 10ms or 10000ns
:local lTime2 [/system clock get time];
:local lTimestamp2 [:timestamp]
:put (“[] Time: $lTime")
:put ("[
] Timestamp: $lTimestamp”)
:put (“[] Time2: $lTime2")
:put ("[
] Timestamp2: $lTimestamp2”)

I also used this to time how long the following calls take:
/system gps monitor once
/interface lte monitor lte1
/interface/monitor-traffic lte1

There is also the :time command. That actually times an operation in it’s command={ # code # } like

:put [:time command={ :delay 1000000000ns }]
00:00:01.001184