rostime call is slow

2 ビュー (過去 30 日間)
Mauro
Mauro 2020 年 11 月 23 日
回答済み: Amrtanshu Raj 2021 年 2 月 5 日
While developing a Matlab wrapper around a ROS package, I noticed that rostime("now") takes around 1.4e-03 s per call. In Python on the other hand the same call only takes 4.8e-06 s. I understand that there might be implementation differences, but Matlab being orders of magnitude slower than Python seems strange. Is there anything I am doing wrong here?
Matlab script for timing:
tic
for i = 1:1000
a = rostime("now");
end
toc / 1000
Python script for timing:
import rospy
import time
if __name__ == "__main__":
rospy.init_node("test")
t0 = time.clock()
for i in range(1000):
a = rospy.Time.now()
t1 = time.clock()
print((t1 - t0) / 1000)
Thanks!
Edit:
I found this bug report and the workaround using robotics.ros.internal.Time([]).CurrentTime is about 10 times faster than rostime("now"). This is better but still not as fast as it should be. I am also not sure how much of a hack this is.

回答 (1 件)

Amrtanshu Raj
Amrtanshu Raj 2021 年 2 月 5 日
Hi,
The difference in computation time is because of the implementation difference between the MATLAB and Python version of the command. Even declaring a static rostime like
time = rostime(2,85000);
Takes around 1.4e-03 seconds to compute. I have brought this to the notice of the developers.
Thanks !!

カテゴリ

Help Center および File ExchangePublishers and Subscribers についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by