I'm a new python programmer and was tasked to do a simple app to make an API call. It's working fine and all but however I am not satisfied with the speed. I have tried it on both slow speed internet connection and faster speed internet connection. On average, the time taken to make the API call ranging from 1.3 to 2.4 sec. I have tested this on 5mbps to 80mbps internet connection and both shown similar result (plus minus 0.5 sec difference).
The time taken doesn't look too bad on paper but however, when I checked in the server where the call was made to, the processing time is only around 0.2 - 0.5 seconds, meaning there's 1 - 2 seconds of time lost during the request process.
Here's the code that I'm using:
import requests
import json
import time
import uuid
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
#get api call start time
startTime = time.time()
#make api call
r=requests.post(APIUrl, data=payload, headers=headers, verify=False)
#get api call finish time
endTime = time.time()
#calculate time taken
totalTimeTaken = str(float(round((endTime - startTime ),3)))
json_obj = r.json(strict=False)
print "Response: "+str(json_obj['response'])
print "Elapsed: "+str(r.elapsed)
print "Time Taken: "+totalTimeTaken