<commit_before>#!/usr/bin/env python

"""
Really simple rudimentary benchmark to compare ConnectionPool versus standard
urllib to demonstrate the usefulness of connection re-using.
"""

import sys
import time
import urllib

sys.path.append('../')
import urllib3


# URLs to download. Doesn't matter as long as they're from the same host, so we
# can take advantage of connection re-using.
TO_DOWNLOAD = [
    'http://code.google.com/apis/apps/',
    'http://code.google.com/apis/base/',
    'http://code.google.com/apis/blogger/',
    'http://code.google.com/apis/calendar/',
    'http://code.google.com/apis/codesearch/',
    'http://code.google.com/apis/contact/',
    'http://code.google.com/apis/books/',
    'http://code.google.com/apis/documents/',
    'http://code.google.com/apis/finance/',
    'http://code.google.com/apis/health/',
    'http://code.google.com/apis/notebook/',
    'http://code.google.com/apis/picasaweb/',
    'http://code.google.com/apis/spreadsheets/',
    'http://code.google.com/apis/webmastertools/',
    'http://code.google.com/apis/youtube/',
]


def urllib_get(url_list):
    assert url_list
    for url in url_list:
        now = time.time()
        r = urllib.urlopen(url)
        elapsed = time.time() - now
        print "Got in %0.3f: %s" % (elapsed, url)


def pool_get(url_list):
    assert url_list
    pool = HTTPConnectionPool.from_url(url_list[0])
    for url in url_list:
        now = time.time()
        r = pool.get_url(url)
        elapsed = time.time() - now
        print "Got in %0.3fs: %s" % (elapsed, url)
<commit_msg>fixed benchmark.py - HTTPConnectionPool no longer has from_url() method<commit_after>#!/usr/bin/env python

"""
Really simple rudimentary benchmark to compare ConnectionPool versus standard
urllib to demonstrate the usefulness of connection re-using.
"""

import sys
import time
import urllib

sys.path.append('../')
import urllib3


# URLs to download. Doesn't matter as long as they're from the same host, so we
# can take advantage of connection re-using.
TO_DOWNLOAD = [
    'http://code.google.com/apis/apps/',
    'http://code.google.com/apis/base/',
    'http://code.google.com/apis/blogger/',
    'http://code.google.com/apis/calendar/',
    'http://code.google.com/apis/codesearch/',
    'http://code.google.com/apis/contact/',
    'http://code.google.com/apis/books/',
    'http://code.google.com/apis/documents/',
    'http://code.google.com/apis/finance/',
    'http://code.google.com/apis/health/',
    'http://code.google.com/apis/notebook/',
    'http://code.google.com/apis/picasaweb/',
    'http://code.google.com/apis/spreadsheets/',
    'http://code.google.com/apis/webmastertools/',
    'http://code.google.com/apis/youtube/',
]


def urllib_get(url_list):
    assert url_list
    for url in url_list:
        now = time.time()
        r = urllib.urlopen(url)
        elapsed = time.time() - now
        print "Got in %0.3f: %s" % (elapsed, url)


def pool_get(url_list):
    assert url_list
    pool = urllib3.connection_from_url(url_list[0])
    for url in url_list:
        now = time.time()
        r = pool.get_url(url)
        elapsed = time.time() - now
        print "Got in %0.3fs: %s" % (elapsed, url)

{'fraction_non_alphanumeric': 0.16406737367436058, 'fraction_numerical': 0.004054897067997504, 'mean_word_length': 2.849939975990396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7614093', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1114, 'n_words': 229}