benchmarks: 1488e1f55f61 (original) (raw)
Mercurial > benchmarks
changeset 201:1488e1f55f61
Issue #17785: Use a faster URL shortener for perf.py
Alexandre Vassalotti alexandre@peadrop.com | |
---|---|
date | Sat, 20 Apr 2013 12:59:46 -0700 |
parents | 134941cc41c0 |
children | 5d4ecadca0d5 |
files | perf.py |
diffstat | 1 files changed, 16 insertions(+), 12 deletions(-)[+] [-] perf.py 28 |
line wrap: on
line diff
--- a/perf.py +++ b/perf.py @@ -54,6 +54,7 @@ from future import division, with_st import csv import contextlib +import json import logging import math import optparse @@ -68,10 +69,9 @@ import tempfile import time import threading try:
try: import multiprocessing except ImportError: @@ -784,21 +784,25 @@ def GetChart(base_data, changed_data, op def ShortenUrl(url):
Args: url: url to shorten. Returns:
Shorter url. If tinyurl.com is not available, returns the original[](#l1.36)
url unaltered.[](#l1.37)
- tinyurl_api = "http://tinyurl.com/api-create.php?url="[](#l1.40) try:
url = urlopen(tinyurl_api + url).read()[](#l1.42)
- except URLError:
info("failed to call out to tinyurl.com")[](#l1.44)
- return url
conn = httpclient.HTTPSConnection("www.googleapis.com")[](#l1.46)
body = json.dumps({"longUrl": url})[](#l1.47)
headers = {"Content-Type": "application/json"}[](#l1.48)
conn.request("POST", "/urlshortener/v1/url", body, headers)[](#l1.49)
response = conn.getresponse()[](#l1.50)
if response.status == httpclient.OK:[](#l1.51)
return json.loads(response.read().decode("utf-8"))["id"][](#l1.52)
- except IOError:
info("failed to call out to URL shortening service")[](#l1.54)
- return None