PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/lib/python/indra/base/cllsd_test.py

https://bitbucket.org/lindenlab/viewer-beta/
Python | 73 lines | 42 code | 9 blank | 22 comment | 4 complexity | f7a19f7c948b5a3a3a5de6c4240a6dfc MD5 | raw file
 1#!/usr/bin/python
 2## 
 3## $LicenseInfo:firstyear=2011&license=viewerlgpl$
 4## Second Life Viewer Source Code
 5## Copyright (C) 2011, Linden Research, Inc.
 6## 
 7## This library is free software; you can redistribute it and/or
 8## modify it under the terms of the GNU Lesser General Public
 9## License as published by the Free Software Foundation;
10## version 2.1 of the License only.
11## 
12## This library is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15## Lesser General Public License for more details.
16## 
17## You should have received a copy of the GNU Lesser General Public
18## License along with this library; if not, write to the Free Software
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20## 
21## Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
22## $/LicenseInfo$
23from indra.base import llsd, lluuid
24from datetime import datetime
25import cllsd
26import time, sys
27
28class myint(int):
29    pass
30
31values = (
32    '&<>',
33    u'\u81acj',
34    llsd.uri('http://foo<'),
35    lluuid.UUID(),
36    llsd.LLSD(['thing']),
37    1,
38    myint(31337),
39    sys.maxint + 10,
40    llsd.binary('foo'),
41    [],
42    {},
43    {u'f&\u1212': 3},
44    3.1,
45    True,
46    None,
47    datetime.fromtimestamp(time.time()),
48    )
49
50def valuator(values):
51    for v in values:
52        yield v
53
54longvalues = () # (values, list(values), iter(values), valuator(values))
55
56for v in values + longvalues:
57    print '%r => %r' % (v, cllsd.llsd_to_xml(v))
58
59a = [[{'a':3}]] * 1000000
60
61s = time.time()
62print hash(cllsd.llsd_to_xml(a))
63e = time.time()
64t1 = e - s
65print t1
66
67s = time.time()
68print hash(llsd.LLSDXMLFormatter()._format(a))
69e = time.time()
70t2 = e - s
71print t2
72
73print 'Speedup:', t2 / t1