Speed up python's struct.unpack

后端 未结 4 856
悲&欢浪女
悲&欢浪女 2021-02-14 07:23

I am trying to speed up my script. It basically reads a pcap file with Velodyne\'s Lidar HDL-32 information and allows me to get X, Y, Z, and Intensity values. I have profiled m

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-14 07:59

    For your specific situation if you can fit your loop into a numpy call, that'd be fastest.

    With that said, for just the struct.unpack part -- if your data happens to native byte order, you can use memoryview.cast. For a short example, it is about 3x faster than naive struct.unpack without any change in logic.

    In [20]: st = struct.Struct("

提交回复
热议问题