From the wikipedia:

Net neutrality is the principle that Internet service providers and governments regulating the Internet should treat all data on the Internet the same, not discriminating or charging differentially by user, content, website, platform, application, type of attached equipment, or mode of communication.

Your task is to find if your internet connection is being throttled by your ISP or if the net is neutral.

What you actually have to do

Your program or function will be run twice. It needs to have some form of memory or storage between its two calls, like writing to a file, a static var in C++, setting a property on a function in JS, or just a global variable.

The first time it is run, it must connect to google.com (a fairly popular site), and a different website with an Alexa rank of greater than 1 million, like unlicense.org.

It must record the time it took google.com to respond*, and the time it took the other website to respond*.

The second time it is run, it must do the above, and print a truthy value if these are both true:

  1. The response time between google.com the first and second time varied by less than 5%. (Google paid ISP to not throttle)
  2. The response time between the other site the first and second time increased by more than 50%. (Other site didn't)

Shortest code wins!

* The time it to get the response body, headers, or just connect with the server. You choose.

  • 2
    \$\begingroup\$ Is there any method you could recommend of finding such a site with an Alexa ranking greater than 1 million? \$\endgroup\$ – notjagan Jul 16 '17 at 22:47
  • \$\begingroup\$ @notjagan done. \$\endgroup\$ – programmer5000 Jul 16 '17 at 23:04
  • \$\begingroup\$ Why the downvotes? \$\endgroup\$ – programmer5000 Jul 16 '17 at 23:04
  • \$\begingroup\$ To clarify, you mean a site with a larger rank and thus lower traffic, right? I at first thought you meant a high rank. \$\endgroup\$ – Rɪᴋᴇʀ Jul 16 '17 at 23:11
  • 1
    \$\begingroup\$ Also, the time to get the full response body is pointless. It will take much longer to download larger bodies than others. Google is likely a much smaller body than unlicense. You should be measuring the time between when the request is submitted, and the first headers are received. \$\endgroup\$ – Zizouz212 Jul 16 '17 at 23:15

Python 3 + requests, 185 bytes

lambda t=[]:t.append([g("http://google.com"),g("http://a.co")])or len(t)>1and abs(1-t[0][0]/t[1][0])<.05<1.5<t[1][1]/t[0][1]
g=lambda s:get(s).elapsed.microseconds
from requests import*

Unfortunately requests doesn't work with TIO, so I'll have to post a link on another service later. Uses http://a.co as the website with a ranking greater than 1 million.

207 bytes, if time is required for the full body

f=lambda t=[]:t.append([g("http://google.com"),g("http://a.co")])or len(t)>1and abs(1-t[0][0]/t[1][0])<.05<1.5<t[1][1]/t[0][1]
def g(s):t=time();get(s);return time()-t
from requests import*
from time import*
  • \$\begingroup\$ Your answer is basically what I wrote too. The problem with the elapsed attribute of a request is that it's the measured time between when the request was submitted outbound, and when the module first started parsing the first response headers that it received. Not the full response body :) \$\endgroup\$ – Zizouz212 Jul 16 '17 at 23:47
  • \$\begingroup\$ @Zizouz212 Wouldn't it make more sense for it to measure the time to response headers? The full body would be dependent on the size of the page and not solely the time to connection. \$\endgroup\$ – notjagan Jul 17 '17 at 0:06
  • \$\begingroup\$ Oh no, I completely agree. I even mentioned it in the comment above on the question as well (I wrote nearly the same answer with python 2 requests). It's just the question wants the time for the response body to arrive as well, which I figured I'd just mention \$\endgroup\$ – Zizouz212 Jul 17 '17 at 0:12
  • \$\begingroup\$ Since requests is an external library that isn't in vanilla Python (which is why it isn't on TIO), officially your header should say Python 3 + [requests](http://docs.python-requests.org/en/master/), just a heads up \$\endgroup\$ – Value Ink Jul 31 '17 at 22:38
  • \$\begingroup\$ @ValueInk But requests is part of vanilla Python - in fact, you can import it on TIO. The problem with it on TIO is you can't actually make requests (i.e. through requests.get) because TIO restricts network access. \$\endgroup\$ – notjagan Jul 31 '17 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.