file seek is slow

Metalone jcb at iteris.com
Thu Mar 11 17:57:28 EST 2010


I just tried the seek test with Cython.
Cython fseek() : 1.059 seconds. 30% slower than 'C'
Python f.seek : 1.458 secondds. 80% slower than 'C'.
It is amazing to me that Cython generates a 'C' file that is 1478
lines.
#Cython code
import time
cdef int SEEK_SET = 0
cdef extern from "stdio.h":
 void* fopen(char* filename, char* mode)
 int fseek(void*, long, int)
def main():
 cdef void* f1 = fopen('video.txt', 'rb')
 cdef int i=1000000
 t0 = time.clock()
 while i > 0:
 fseek(f1, 0, SEEK_SET)
 i -= 1
 delta = time.clock() - t0
 print "%.3f" % delta
if __name__ == '__main__':
 main()


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /