-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathget.py
41 lines (34 loc) · 928 Bytes
/
get.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'''
Performance Comparison between requests and pycurl
'''
import time
import requests
import pycurl
from io import BytesIO
def pycurl_get():
b = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://httpbin.org/ip')
c.setopt(c.WRITEDATA, b)
c.perform()
c.close()
body = b.getvalue()
print('pycurl_get: %s' % body.decode('utf8'))
def requests_get():
r = requests.get('https://httpbin.org/ip')
print('requests_get: %s' % r.text)
def main():
start_time = time.time()
for i in range(100):
requests_get()
end_time = time.time()
request_time = end_time - start_time
start_time = time.time()
for i in range(100):
pycurl_get()
end_time = time.time()
pycurl_time = end_time - start_time
print('The requests_get takes %f' % request_time)
print('The pycurl_get takes %f' % pycurl_time)
if __name__ == '__main__':
main()