Debian Codegraph @

test/test1.py

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