| 568 | print(' improvement factor: %.2f' % (t1/t2, )) |
| 569 | |
| 570 | def fetch(N, url, delay=0): |
| 571 | import time |
| 572 | lens = [] |
| 573 | starttime = time.time() |
| 574 | for i in _range(N): |
| 575 | if delay and i > 0: time.sleep(delay) |
| 576 | fo = _urllib.request.urlopen(url) |
| 577 | foo = fo.read() |
| 578 | fo.close() |
| 579 | lens.append(len(foo)) |
| 580 | diff = time.time() - starttime |
| 581 | |
| 582 | j = 0 |
| 583 | for i in lens[1:]: |
| 584 | j = j + 1 |
| 585 | if not i == lens[0]: |
| 586 | print("WARNING: inconsistent length on read %i: %i" % (j, i)) |
| 587 | |
| 588 | return diff |
| 589 | |
| 590 | def test_timeout(url): |
| 591 | global DEBUG |