Python Forum
python 3 TextIOWrapper.tell() is significantly slower than in python 2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python 3 TextIOWrapper.tell() is significantly slower than in python 2
#1
Hi, I'm having a function ported from python 2 to python 3 and found that the TextIOWrapper.tell() is the cause that notably slows down the perfomance.

import timeit
f=open('file')
timeit.timeit(f.tell)
In python 3, the execution time of above code example is roughly 0.58s, while in python 2 it's only 0.07s.

Is there any workaround to solve this problem?
Reply
#2
tell is a simple instruction that gets the byte offset from beginning of file, and should not be slow at all
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> fp = open('woogie.txt')
>>> def testtime():
...     s = time.time()
...     fp.tell()
...     e = time.time()
...     print(f'eplapsed time: {e - s}')
... 
>>> testtime()
eplapsed time: 1.0251998901367188e-05
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020