File: test1.py

package info (click to toggle)
cerealizer 0.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 176 kB
  • sloc: python: 359; makefile: 6
file content (120 lines) | stat: -rw-r--r-- 2,509 bytes parent folder | download | duplicates (5)
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
# Cerealizer
# Copyright (C) 2005 Jean-Baptiste LAMY
#
# This program is free software.
# It is available under the Python licence.

# Small benchmark

from __future__ import print_function

import cerealizer



import time
#import psyco
#psyco.full()

class O(object):
  def __init__(self):
    self.x = 1
    self.s = "jiba"
    self.o = None
    self.l = [1, 2, 3, 4]
    
cerealizer.register(O)
cerealizer.freeze_configuration()


l = []
for i in range(20000):
  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,", len(s), "bytes length")

t = time.time()
l2 = cerealizer.loads(s)
print("loads in", time.time() - t, "s")


import pickle

print()
print("pickle")
t = time.time()
s = pickle.dumps(l)
print("dumps in", time.time() - t, "s,", len(s), "bytes length")

t = time.time()
l2 = pickle.loads(s)
print("loads in", time.time() - t, "s")

import cPickle

print()
print("cPickle")
t = time.time()
s = cPickle.dumps(l)
print("dumps in", time.time() - t, "s,", len(s), "bytes length")

t = time.time()
l2 = cPickle.loads(s)
print("loads in", time.time() - t, "s")


import twisted.spread.jelly, twisted.spread.banana

class O(object, twisted.spread.jelly.Jellyable, twisted.spread.jelly.Unjellyable):
  def __init__(self):
    self.x = 1
    self.s = "jiba"
    self.o = None
    self.l = [1, 2, 3, 4]
    
cerealizer.register(O)
cerealizer.freeze_configuration()


l = []
for i in range(20000):
  o = O()
  if l: o.o = l[-1]
  l.append(o)


print()
print("jelly + banana")
t = time.time()
s = twisted.spread.banana.encode(twisted.spread.jelly.jelly(l))
print("dumps in", time.time() - t, "s,", 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,", len(s), "bytes length")

t = time.time()
l2 = twisted.spread.jelly.unjelly(twisted.spread.banana.decode(s))
print("loads in", time.time() - t, "s")