1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
# Cerealizer
# Copyright (C) 2005 Jean-Baptiste LAMY
#
# This program is free software.
# It is available under the Python licence.
# Small benchmark
import cerealizer
import twisted.spread.jelly, twisted.spread.banana
import cPickle, pickle
import time
import psyco
psyco.full()
class O(object, twisted.spread.jelly.Jellyable, twisted.spread.jelly.Unjellyable):
def __init__(self):
self.x = 1
self.s = "jiba"
self.o = None
# def getStateFor(self, jellier):
# return self.__dict__
# def setStateFor(self, unjellier, state):
# self.__dict__ = state
# def _unjellyable_factory(clazz, state):
# o = clazz.__new__(clazz)
# o.__dict__ = state
# return o
# _unjellyable_factory = classmethod(_unjellyable_factory)
cerealizer.register(O)
cerealizer.freeze_configuration()
l = []
for i in range(2000):
o = O()
if l: o.o = l[-1]
l.append(o)
print "cerealizer"
t = time.time()
s = cerealizer.dumps(l)
print "dumps in", time.time() - t, "s,",
print len(s), "bytes length"
t = time.time()
l2 = cerealizer.loads(s)
print "loads in", time.time() - t, "s"
print
print "cPickle"
t = time.time()
s = cPickle.dumps(l)
print "dumps in", time.time() - t, "s,",
print len(s), "bytes length"
t = time.time()
l2 = cPickle.loads(s)
print "loads in", time.time() - t, "s"
print
print "pickle"
t = time.time()
s = pickle.dumps(l)
print "dumps in", time.time() - t, "s,",
print len(s), "bytes length"
t = time.time()
l2 = pickle.loads(s)
print "loads in", time.time() - t, "s"
print
print "jelly + banana"
t = time.time()
s = twisted.spread.banana.encode(twisted.spread.jelly.jelly(l))
print "dumps in", time.time() - t, "s",
print len(s), "bytes length"
t = time.time()
l2 = twisted.spread.jelly.unjelly(twisted.spread.banana.decode(s))
print "loads in", time.time() - t, "s"
import twisted.spread.cBanana
twisted.spread.banana.cBanana = twisted.spread.cBanana
twisted.spread.cBanana.pyb1282int=twisted.spread.banana.b1282int
twisted.spread.cBanana.pyint2b128=twisted.spread.banana.int2b128
twisted.spread.banana._i = twisted.spread.banana.Canana()
twisted.spread.banana._i.connectionMade()
twisted.spread.banana._i._selectDialect("none")
print
print "jelly + cBanana"
t = time.time()
s = twisted.spread.banana.encode(twisted.spread.jelly.jelly(l))
print "dumps in", time.time() - t, "s",
print len(s), "bytes length"
t = time.time()
l2 = twisted.spread.jelly.unjelly(twisted.spread.banana.decode(s))
print "loads in", time.time() - t, "s"
|