0

I have a list of domains and I need to get some stat for example average response time for the index page of each site about them.

I wanna to get the Time To First Byte for each domain. I searched a little but I did not find any complete answer to my question. Here is my funtion for calculating the response time of a host:

opener = urllib2.build_opener()


request = urllib2.Request("http://"+host)


start = time.time()


resp = opener.open(request)


# read one byte


resp.read(1)


ttfb = time.time() - start


# read the rest


resp.read()


ttlb = time.time() - start


print "The TTFirst Byte of " +host+"is:"+ttlb

When I run it for google.com for example, I got this error:

google.com not found

Stateless
  • 293
  • 2
  • 4
  • 18
  • What are you asking for help with? Have you tried implementing anything yet? You could `for` loop through the domains that you want to probe and `print` the output to the command line? – Ari Cooper-Davis Mar 12 '17 at 17:28
  • Hi @AriCooper-Davis, I edited my question. Do you have any idea about my error? – Stateless Mar 13 '17 at 12:10

1 Answers1

2

When you post a question you need to include a Minimal, Complete, and Verifiable example of your code. Your code is none of these things. If I do the simple importing of libraries and defining of variables that would be required to create a Minimal, Complete, and Verifiable example of your code then it runs fine:

import time
import urllib2

host = "http://google.com"
opener = urllib2.build_opener()
request = urllib2.Request(host)
start = time.time()
resp = opener.open(request)
# read one byte
resp.read(1)
ttfb = time.time() - start
# read the rest
resp.read()
ttlb = time.time() - start

print "The TTFirst Byte of " +host+" is: "+str(ttlb)

Returns:

The TTFirst Byte of http://google.com is: 1.25
Community
  • 1
  • 1
Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43
  • This works for me. Can you please give me the url which I can put a + point on your answer? – Stateless Mar 14 '17 at 06:46
  • I don't understand your question, what url are you looking for? You can mark my answer correct by pressing the tick to the left of my answer. – Ari Cooper-Davis Mar 14 '17 at 12:19
  • ok, I am so sorry for my bad English! It seems that I don't have enough reputation for marking the answers. Otherwise, I will mark your answer whenever it is possible for me. – Stateless Mar 14 '17 at 12:36
  • Don't worry! You can definitely accept an answer. Look at this diagram to see how to accept answers :-) https://meta.stackexchange.com/a/5235 – Ari Cooper-Davis Mar 14 '17 at 12:51