Skip to main content
  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

       forwith open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library to guarantee that you will not overwrite an existing file.

  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

       for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library to guarantee that you will not overwrite an existing file.

  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

       with open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library to guarantee that you will not overwrite an existing file.

edited body
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
  • Upload vs. download speed: Residential Internet connections tend to significantly favour downloads, since that's what most consumers care about.
  • Traffic shaping: Some ISPs will throttle the bandwidth to penalize very large transfers, so that smaller responses feel more responsive.
  • Server performance: It does take a few milliseconds for Google's server to formulate the response payload; that delay would be a more significant fraction of the measured round-trip time for a short response than for a long response.
  • HTTP and HTTPS overhead: You're considering only the size of the HTTP response payload. Since you're using HTTPS, there are also multiple TCP round trips needed to perform the TLS handshake, and a few kilobytes to transfer the certificates. The HTTP headers could add another kilobyte or so. All of this is significant when the payload is only ~10 kB short.
  • DNS overhead: Resolving the google.com hostname to an IP address might involve a DNS lookup, which would add a few milliseconds. The time for that DNS lookup is accounted for in your benchmark, but not the traffic.
  • Proximity: The "Internet" is not one entity. Connectivity to various parts of the Internet will have different performance characteristics.
  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

       for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library, to guarantee that you will not overwrite an existing file.

  • Upload vs. download speed: Residential Internet connections tend to significantly favour downloads, since that's what most consumers care about.
  • Traffic shaping: Some ISPs will throttle the bandwidth to penalize very large transfers, so that smaller responses feel more responsive.
  • Server performance: It does take a few milliseconds for Google's server to formulate the response payload; that delay would be a more significant fraction of the measured round-trip time for a short response than for a long response.
  • HTTP overhead: You're considering only the size of the HTTP response payload. Since you're using HTTPS, there are also multiple TCP round trips needed to perform the TLS handshake, and a few kilobytes to transfer the certificates. The HTTP headers could add another kilobyte or so. All of this is significant when the payload is only ~10 kB short.
  • Proximity: The "Internet" is not one entity. Connectivity to various parts of the Internet will have different performance characteristics.
  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

       for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library, to guarantee that you will not overwrite an existing file.

  • Upload vs. download speed: Residential Internet connections tend to significantly favour downloads, since that's what most consumers care about.
  • Traffic shaping: Some ISPs will throttle the bandwidth to penalize very large transfers, so that smaller responses feel more responsive.
  • Server performance: It does take a few milliseconds for Google's server to formulate the response payload; that delay would be a more significant fraction of the measured round-trip time for a short response than for a long response.
  • HTTP and HTTPS overhead: You're considering only the size of the HTTP response payload. Since you're using HTTPS, there are also multiple TCP round trips needed to perform the TLS handshake, and a few kilobytes to transfer the certificates. The HTTP headers could add another kilobyte or so. All of this is significant when the payload is only ~10 kB short.
  • DNS overhead: Resolving the google.com hostname to an IP address might involve a DNS lookup, which would add a few milliseconds. The time for that DNS lookup is accounted for in your benchmark, but not the traffic.
  • Proximity: The "Internet" is not one entity. Connectivity to various parts of the Internet will have different performance characteristics.
  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

       for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library to guarantee that you will not overwrite an existing file.

Code indentation.
Source Link
ferada
  • 11.1k
  • 25
  • 63
  • Upload vs. download speed: Residential Internet connections tend to significantly favour downloads, since that's what most consumers care about.
  • Traffic shaping: Some ISPs will throttle the bandwidth to penalize very large transfers, so that smaller responses feel more responsive.
  • Server performance: It does take a few milliseconds for Google's server to formulate the response payload; that delay would be a more significant fraction of the measured round-trip time for a short response than for a long response.
  • ProtocolHTTP overhead: You're considering only the size of the HTTP response payload. Since you're using HTTPS, there are also multiple TCP round trips needed to perform the TLS handshake, and a few kilobytes to transfer the certificates. The HTTP headers could add another kilobyte or so. All of this is significant when the payload is only ~10 kB short.
  • Proximity: The "Internet" is not one entity. Connectivity to various parts of the Internet will have different performance characteristics.
  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

    for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f: f.write(x)

       for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library, to guarantee that you will not overwrite an existing file.

  • Upload vs. download speed: Residential Internet connections tend to significantly favour downloads, since that's what most consumers care about.
  • Traffic shaping: Some ISPs will throttle the bandwidth to penalize very large transfers, so that smaller responses feel more responsive.
  • Server performance: It does take a few milliseconds for Google's server to formulate the response payload; that delay would be a more significant fraction of the measured round-trip time for a short response than for a long response.
  • Protocol overhead: You're considering only the size of the HTTP response payload. Since you're using HTTPS, there are also multiple TCP round trips needed to perform the TLS handshake, and a few kilobytes to transfer the certificates. The HTTP headers could add another kilobyte or so. All of this is significant when the payload is only ~10 kB short.
  • Proximity: The "Internet" is not one entity. Connectivity to various parts of the Internet will have different performance characteristics.
  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

    for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f: f.write(x)

  • To generate temporary files, use the tempfile library, to guarantee that you will not overwrite an existing file.

  • Upload vs. download speed: Residential Internet connections tend to significantly favour downloads, since that's what most consumers care about.
  • Traffic shaping: Some ISPs will throttle the bandwidth to penalize very large transfers, so that smaller responses feel more responsive.
  • Server performance: It does take a few milliseconds for Google's server to formulate the response payload; that delay would be a more significant fraction of the measured round-trip time for a short response than for a long response.
  • HTTP overhead: You're considering only the size of the HTTP response payload. Since you're using HTTPS, there are also multiple TCP round trips needed to perform the TLS handshake, and a few kilobytes to transfer the certificates. The HTTP headers could add another kilobyte or so. All of this is significant when the payload is only ~10 kB short.
  • Proximity: The "Internet" is not one entity. Connectivity to various parts of the Internet will have different performance characteristics.
  • By PEP 8, getInternetSpeed() should be get_internet_speed(). The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.

  • For filename manipulation, use the os.path module.

  • Avoid redefining variables, especially in a way that changes their type:

    x = urllib2.urlopen('https://google.com')
    …
    x = x.read()
    

    x is a very poor variable name, by the way. I suggest req.

  • open() should almost always be used in the context of a with block, so that the closure will be handled correctly for you:

       for open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f:
           f.write(x)
    
  • To generate temporary files, use the tempfile library, to guarantee that you will not overwrite an existing file.

Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Loading