PageRenderTime 143ms CodeModel.GetById 80ms app.highlight 4ms RepoModel.GetById 56ms app.codeStats 0ms

/mysql_watcher/indra/base/cllsd_test.py

https://bitbucket.org/lindenlab/apiary/
Python | 76 lines | 42 code | 10 blank | 24 comment | 4 complexity | f6569961f870eef477d9cf91ddad9296 MD5 | raw file
 1#
 2# $LicenseInfo:firstyear=2010&license=mit$
 3# 
 4# Copyright (c) 2010, Linden Research, Inc.
 5# 
 6# Permission is hereby granted, free of charge, to any person obtaining a copy
 7# of this software and associated documentation files (the "Software"), to deal
 8# in the Software without restriction, including without limitation the rights
 9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12# 
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15# 
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23# $/LicenseInfo$
24#
25
26from indra.base import llsd, lluuid
27from datetime import datetime
28import cllsd
29import time, sys
30
31class myint(int):
32    pass
33
34values = (
35    '&<>',
36    u'\u81acj',
37    llsd.uri('http://foo<'),
38    lluuid.UUID(),
39    llsd.LLSD(['thing']),
40    1,
41    myint(31337),
42    sys.maxint + 10,
43    llsd.binary('foo'),
44    [],
45    {},
46    {u'f&\u1212': 3},
47    3.1,
48    True,
49    None,
50    datetime.fromtimestamp(time.time()),
51    )
52
53def valuator(values):
54    for v in values:
55        yield v
56
57longvalues = () # (values, list(values), iter(values), valuator(values))
58
59for v in values + longvalues:
60    print '%r => %r' % (v, cllsd.llsd_to_xml(v))
61
62a = [[{'a':3}]] * 1000000
63
64s = time.time()
65print hash(cllsd.llsd_to_xml(a))
66e = time.time()
67t1 = e - s
68print t1
69
70s = time.time()
71print hash(llsd.LLSDXMLFormatter()._format(a))
72e = time.time()
73t2 = e - s
74print t2
75
76print 'Speedup:', t2 / t1