Python string processing optimization

前端 未结 2 2036
再見小時候
再見小時候 2020-12-05 22:23

So lately I\'ve been making a python script for extracting data from a large text files ( > 1 GB ). The problem basically sums up to selecting lines of text from the file, a

2条回答
  •  自闭症患者
    2020-12-05 23:07

    Think about calling an external process (grep and the like) to speed up processing and reducing the data volume you have to handle within Python.

    Another route to go would be to filter or pre-filter your data with a compiled regex, since then your inner loop uses the optimized code of the standard library.

    You could also try Cython or similar for the hot inner loops, see e.g. https://books.google.de/books?id=QSsOBQAAQBAJ&dq=high+perf+python&hl=en for details on that.

提交回复
热议问题