from __future__ import with_statement from timer import timer import redis import time r = redis.StrictRedis() t = time.time n = 10000 with timer: for i in xrange(n): r.sadd('test', str(i % 1000)) r.srem('test', str((i + 500) % 1000)) r.delete('test') print timer.duration() / n / 2
'nick': 'nick_nick_nick', 'auth': True, 'username': '******', 'ip': '127.0.0.1', 'id': '[email protected]', 'modes': ['i', 'a', 'b', ('k', '1235')], 'timestamp': 123456789 } n = 10000 for lib in [cPickle, json, simplejson, cjson, ujson, msgpack, marshal]: print lib.__name__ with timer: for i in xrange(n): serialized = lib.dumps(data) print ' size', len(serialized) print ' dumps', n / timer.duration() serialized = lib.dumps(data) with timer: for i in xrange(n): lib.loads(serialized) print ' loads', n / timer.duration() print '(actions per second)'