urllib.request.urlopen a lot slower than cpython
This is the benchmark:
import time
try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen
try:
clock = time.process_time
except:
clock = time.clock
l = []
for _ in range(10):
t0 = clock()
for i in range(100):
urlopen("https://www.python.org")
t1 = clock()
print("Next: %.2f" % (t1 - t0))
l.append(t1-t0)
print("Average: %.2f" % (sum(l)/len(l)))
For my setup the answer is around 4x slower than cpython (experiment-with-ffi-addresses helps around 10%) on py3.7 branch.
The issues are:
- indiscrimante use of memoryview in httplib
- recv_into being slow
- intermediate raw buffers allocated and not freed on time (neither memory pressure is increased nor they're freed in time) in _io module
- possibly more