This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import timeit as t | |
# 1 << 24 = 16 million elements | |
# Python 2.7 | |
>>> t('needle in x', 'x, needle = range(1<<24), 1<<10') | |
13.510631084442139 | |
>>> t('x.index(needle)', 'x, needle = range(1<<24), 1<<10') | |
14.749315023422241 | |
>>> t('needle in x', 'x, needle = set(range(1<<24)), 1<<10') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Microbenchmarks using jsonschema in Python (2.7.5, 3.3.2) and pypy 2.1 | |
## Common code | |
import jsonschema | |
schema = { | |
'type': 'object', | |
'properties': { | |
'weight': {'type': 'integer', 'minimum': 1}, | |
'hosts': {'type': 'array', 'minItems': 1, 'items': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Microbenchmark of small string concatenation methods in Python 2.7.5, Python 3.3.2, and pypy-2.1 | |
## Python 2.7.5 | |
In [1]: %timeit '{0}/{1}'.format('taco', 'bell') | |
1000000 loops, best of 3: 226 ns per loop | |
In [2]: %timeit '{}/{}'.format('taco', 'bell') | |
1000000 loops, best of 3: 366 ns per loop | |
In [3]: %timeit '%s/%s' % ('taco', 'bell') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A benchmark comparing different ways of extracting a scheme from a URI in Python | |
# common code | |
# import statements | |
uri = 'redis://localhost:27017' | |
# pypy-2.1: after warm up | |
In [12]: %timeit urlparse.urlparse(uri).scheme | |
1000000 loops, best of 3: 298 ns per loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alejandro@rainbow-generator:~:$ http get localhost:8000/v1/shards?detailed=TrueHTTP/1.1 200 OK | |
Connection: close | |
Content-Length: 347 | |
Content-Location: /v1/shards?detailed=True | |
Content-Type: application/json; charset=utf-8 | |
Date: Tue, 05 Nov 2013 17:11:36 GMT | |
Server: gunicorn/18.0 | |
{ | |
"shards": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""summarize: Given Tsung's HTTP Return Code table saved in a file, outputs: | |
=================== | |
Summary: % of Total | |
=================== | |
{200: 0.03223020521177586, | |
201: 0.6133764139909427, | |
204: 0.3496694087548634, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
try: | |
import pymongo | |
except ImportError: | |
print('error: missing `pymongo`: `pip install pymongo`') | |
quit() | |
import sys | |
remove_set = ['messages', 'queues', 'catalogue'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import socket | |
# Handles only counter events | |
stats_capture = re.compile(r'^(.*):(\d+)\|c$') | |
s = socket.socket(socket.AF_INET, | |
socket.SOCK_DGRAM) | |
s.bind(('127.0.0.1', 8001)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wrap(app): | |
def middleware(env, start_response): | |
path = env['PATH_INFO'] | |
is_forwarded = env['HTTP_X_FORWARDED_FOR']: | |
if is_forwarded and path == '/v1/health': | |
return start_response('200 OK', []) | |
return app(env, start_response) | |
return middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
import uuid | |
import pyrax | |
pyrax.set_credential_file('/whatever') | |
pyrax.queues.client_id = str(uuid.uuid4()) |
OlderNewer