Skip to content

Instantly share code, notes, and snippets.

@teepark
teepark / gist:209702
Created October 14, 2009 00:49
my .zshrc
# The following lines were added by compinstall
zstyle :compinstall filename '/home/travis/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=5000
SAVEHIST=1000
from struct import pack, unpack
def encode(ip_address):
return unpack('i', ''.join([pack('B', int(sub)) for sub in ip_address.split('.')]))[0]
def decode(packed_address):
return '.'.join(['%d' % unpack('B', sub)[0] for sub in pack('i', packed_address)])
(pyyajl) 0 bromium[1044]:~/projects/py-yajl> python compare.py
yajl serialize: 0.442 deserialize: 1.137 total: 1.579
cjson serialize: 0.640 deserialize: 0.265 total: 0.906
simplejson serialize: 1.457 deserialize: 1.104 total: 2.561
stdlib json serialize: 5.951 deserialize: 17.412 total: 23.364
(pyyajl) 0 bromium[1045]:~/projects/py-yajl> deactivate; git checkout py3k; python3 compare.py
Switched to branch 'py3k'
yajl serialize: 1.331 deserialize: 0.878 total: 2.209
stdlib json serialize: 1.291 deserialize: 1.398 total: 2.688
somehow the 3.1 branch is seeing an improvement in decoding (can't explain that), and a slowdown in encoding
python 2.6:
yajl serialize: 0.359 deserialize: 0.442 total: 0.801
yajl serialize: 0.359 deserialize: 0.433 total: 0.792
yajl serialize: 0.366 deserialize: 0.434 total: 0.800
yajl serialize: 0.363 deserialize: 0.426 total: 0.788
yajl serialize: 0.357 deserialize: 0.437 total: 0.794
yajl serialize: 0.364 deserialize: 0.423 total: 0.787
yajl serialize: 0.356 deserialize: 0.420 total: 0.776
This is ApacheBench, Version 2.3 <: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
// subclassing AND instantiating
// (lazy lookups via prototype chain)
function clone(parent, extra) {
var child;
function klass() {};
klass.prototype = parent;
child = extra ? extend(new klass(), extra) : new klass();
__all__ = ["DEFAULT_SIZE", "cache"]
DEFAULT_SIZE = 1024
class _cachedobject(object):
__slots__ = ["prev", "key", "value", "next"]
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)
import functools
class TimerMiddleware(object):
'a WSGI middleware that sends an X-Response-Time header'
def __init__(self, app):
self.app = app
def start_response(self, default, start_time, status, headers):
headers = headers[:] + [('X-Response-Time', time.time() - start_time)]
return default(status, headers)
def bsearch(lst, item):
bottom, top = 0, len(lst)
while top - bottom >= 3:
mid = (top + bottom) // 2
c = cmp(item, lst[mid])
if c < 0:
top = mid
#!/usr/bin/env python
# vim: fileencoding=utf8:et:sta:ai:sw=4:ts=4:sts=4
import time
import greenhouse
import eventlet
import gevent
import gogreen.coro