擅长:python、mysql、java
<p>我也没有做过任何测量,但是因为听起来您已经在用C方法解决Python中的问题,所以您可能需要看一下<a href="http://docs.python.org/library/mmap.html" rel="nofollow noreferrer">Python's built-in ^{<cd1>} library</a>:</p>
<blockquote>
<p>Memory-mapped file objects behave like both strings and like file objects. Unlike normal string objects, however, these are mutable. You can use mmap objects in most places where strings are expected; for example, you can use the re module to search through a memory-mapped file. Since they’re mutable, you can change a single character by doing obj[index] = 'a', or change a substring by assigning to a slice: obj[i1:i2] = '...'. You can also read and write data starting at the current file position, and seek() through the file to different positions.</p>
</blockquote>
<p>我不确定你的问题是否就是你想要的。值得重复的是,你需要做一些测量。<a href="http://docs.python.org/library/timeit.html" rel="nofollow noreferrer">Python's ^{<cd2>} library</a>很容易使用,但也有<a href="http://docs.python.org/library/profile.html#module-cProfile" rel="nofollow noreferrer">^{<cd3>}</a>或<code>hotshot</code>,尽管<code>hotshot</code>有可能被从标准库中删除。</p>