-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench.py
65 lines (42 loc) · 1.41 KB
/
bench.py
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
import sys
import colander
from covador import Map, List, Tuple
class Friend(colander.TupleSchema):
rank = colander.SchemaNode(colander.Int(),
validator=colander.Range(0, 9999))
name = colander.SchemaNode(colander.String())
class Phone(colander.MappingSchema):
location = colander.SchemaNode(
colander.String(),
validator=colander.OneOf(['home', 'work']))
number = colander.SchemaNode(colander.String())
class Friends(colander.SequenceSchema):
friend = Friend()
class Phones(colander.SequenceSchema):
phone = Phone()
class Person(colander.MappingSchema):
name = colander.SchemaNode(colander.String())
age = colander.SchemaNode(colander.Int(),
validator=colander.Range(0, 200))
friends = Friends()
phones = Phones()
schema = Person()
cs = Map({'name': str,
'age': int,
'friends': [(int, str)],
'phones': [{'location': str, 'number': str}]})
cstruct = {
'name': 'keith',
'age': '20',
'friends': [('1', 'jim'), ('2', 'bob'), ('3', 'joe'), ('4', 'fred')],
'phones': [{'location': 'home', 'number': '555-1212'},
{'location': 'work', 'number': '555-8989'}],
}
def test_colander():
schema.deserialize(cstruct)
def test_covador():
cs(cstruct)
if __name__ == '__main__':
f = globals()[sys.argv[1]]
for _ in xrange(50000):
f()