Speed up python's struct.unpack

后端 未结 4 720
别那么骄傲
别那么骄傲 2021-02-14 07:37

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条回答
  •  灰色年华
    2021-02-14 08:00

    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("

提交回复
热议问题