gen_benchmark_config.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import json
  4. from spyne import AnyUri, Unicode, ComplexModel, M, UnsignedInteger16, Array
  5. from spyne.protocol.json import JsonDocument
  6. from spyne.util.dictdoc import get_object_as_dict
  7. class BenchmarkConfigElement(ComplexModel):
  8. # exclude this from the output document
  9. key = Unicode(pa={JsonDocument: dict(exc=True)})
  10. display_name = M(Unicode)
  11. notes = Unicode
  12. versus = Unicode
  13. db_url = AnyUri
  14. json_url = AnyUri
  15. query_url = AnyUri
  16. fortune_url = AnyUri
  17. update_url = AnyUri
  18. plaintext_url = AnyUri
  19. port = M(UnsignedInteger16(default=8080))
  20. approach = M(Unicode(values=['Realistic', 'Stripped'], default='Realistic'))
  21. classification = M(Unicode(values=['Micro', 'Fullstack', 'Platform'], default='Micro'))
  22. database = M(Unicode(values=['none', 'mongodb', 'postgres', 'mysql'], default='none'))
  23. orm = M(Unicode(values=['Full', 'Micro', 'None', 'Raw']))
  24. framework = M(Unicode)
  25. language = M(Unicode)
  26. flavor = M(Unicode)
  27. platform = M(Unicode)
  28. webserver = M(Unicode)
  29. os = M(Unicode(default='Linux'))
  30. database_os = M(Unicode(default='Linux'))
  31. class BenchmarkConfig(ComplexModel):
  32. framework = M(Unicode)
  33. tests = Array(BenchmarkConfigElement, wrapped=False)
  34. gen_raw_test = lambda: BenchmarkConfigElement(
  35. display_name="Spyne RAW",
  36. db_url="/dbsraw",
  37. query_url="/dbraw?queries=",
  38. fortune_url="/fortunesraw",
  39. update_url="/raw-updates?queries=",
  40. orm='Raw',
  41. )
  42. gen_normal_test = lambda: BenchmarkConfigElement(
  43. display_name="Spyne ORM",
  44. db_url="/dbs",
  45. query_url="/db?queries=",
  46. fortune_url="/fortunes",
  47. update_url="/updatesraw?queries=",
  48. orm='Full',
  49. )
  50. def add_common(bc):
  51. bc.port = 8080
  52. bc.approach = "Realistic"
  53. bc.classification = "Micro"
  54. bc.database = "postgres"
  55. bc.framework = "spyne"
  56. bc.language = "Python"
  57. bc.platform = "Spyne"
  58. bc.webserver = "None"
  59. bc.os = "Linux"
  60. bc.database_os = "Linux"
  61. bc.versus = "wsgi"
  62. bc.plaintext_url = "/plaintext"
  63. return bc
  64. config = BenchmarkConfig(framework='spyne', tests=[])
  65. keys = iter(['default', 'raw', 'py3orm', 'py3raw'])
  66. for flav in ['CPython', 'Python3']:
  67. bc = add_common(gen_normal_test())
  68. bc.flavor = flav
  69. bc.key = next(keys)
  70. config.tests.append(bc)
  71. bc = add_common(gen_raw_test())
  72. bc.flavor = flav
  73. bc.key = next(keys)
  74. config.tests.append(bc)
  75. data = get_object_as_dict(config, complex_as=dict)
  76. data['tests'] = [{d['key']: d} for d in data['tests']]
  77. data = json.dumps(data, indent=2, sort_keys=True, separators=(',', ': '))
  78. open('benchmark_config.json', 'wb').write(data)
  79. print(data)