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

https://bitbucket.org/lindenlab/viewer-beta/ · Python · 73 lines · 42 code · 9 blank · 22 comment · 2 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$
  23. from indra.base import llsd, lluuid
  24. from datetime import datetime
  25. import cllsd
  26. import time, sys
  27. class myint(int):
  28. pass
  29. values = (
  30. '&<>',
  31. u'\u81acj',
  32. llsd.uri('http://foo<'),
  33. lluuid.UUID(),
  34. llsd.LLSD(['thing']),
  35. 1,
  36. myint(31337),
  37. sys.maxint + 10,
  38. llsd.binary('foo'),
  39. [],
  40. {},
  41. {u'f&\u1212': 3},
  42. 3.1,
  43. True,
  44. None,
  45. datetime.fromtimestamp(time.time()),
  46. )
  47. def valuator(values):
  48. for v in values:
  49. yield v
  50. longvalues = () # (values, list(values), iter(values), valuator(values))
  51. for v in values + longvalues:
  52. print '%r => %r' % (v, cllsd.llsd_to_xml(v))
  53. a = [[{'a':3}]] * 1000000
  54. s = time.time()
  55. print hash(cllsd.llsd_to_xml(a))
  56. e = time.time()
  57. t1 = e - s
  58. print t1
  59. s = time.time()
  60. print hash(llsd.LLSDXMLFormatter()._format(a))
  61. e = time.time()
  62. t2 = e - s
  63. print t2
  64. print 'Speedup:', t2 / t1