z_all_x_bench_test.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // +build alltests
  2. // +build go1.7
  3. // +build x
  4. // +build !generated
  5. // Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
  6. // Use of this source code is governed by a MIT license found in the LICENSE file.
  7. package codec
  8. // see notes in z_all_bench_test.go
  9. import "testing"
  10. // Note: The following cannot parse TestStruc effectively,
  11. // even with changes to remove arrays and minimize integer size to fit into int64 space.
  12. //
  13. // So we exclude them, listed below:
  14. // encode: gcbor, xdr
  15. // decode: gcbor, vmsgpack, xdr, sereal
  16. func benchmarkXGroup(t *testing.B) {
  17. benchmarkDivider()
  18. t.Run("Benchmark__JsonIter___Encode", Benchmark__JsonIter___Encode)
  19. t.Run("Benchmark__Bson_______Encode", Benchmark__Bson_______Encode)
  20. t.Run("Benchmark__Mgobson____Encode", Benchmark__Mgobson____Encode)
  21. t.Run("Benchmark__VMsgpack___Encode", Benchmark__VMsgpack___Encode)
  22. // t.Run("Benchmark__Gcbor______Encode", Benchmark__Gcbor______Encode)
  23. // t.Run("Benchmark__Xdr________Encode", Benchmark__Xdr________Encode)
  24. t.Run("Benchmark__Sereal_____Encode", Benchmark__Sereal_____Encode)
  25. benchmarkDivider()
  26. t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode)
  27. t.Run("Benchmark__Bson_______Decode", Benchmark__Bson_______Decode)
  28. t.Run("Benchmark__Mgobson____Decode", Benchmark__Mgobson____Decode)
  29. // t.Run("Benchmark__VMsgpack___Decode", Benchmark__VMsgpack___Decode)
  30. // t.Run("Benchmark__Gcbor______Decode", Benchmark__Gcbor______Decode)
  31. // t.Run("Benchmark__Xdr________Decode", Benchmark__Xdr________Decode)
  32. // t.Run("Benchmark__Sereal_____Decode", Benchmark__Sereal_____Decode)
  33. }
  34. func benchmarkCodecXGroup(t *testing.B) {
  35. benchmarkDivider()
  36. t.Run("Benchmark__Msgpack____Encode", Benchmark__Msgpack____Encode)
  37. t.Run("Benchmark__Binc_______Encode", Benchmark__Binc_______Encode)
  38. t.Run("Benchmark__Simple_____Encode", Benchmark__Simple_____Encode)
  39. t.Run("Benchmark__Cbor_______Encode", Benchmark__Cbor_______Encode)
  40. t.Run("Benchmark__Json_______Encode", Benchmark__Json_______Encode)
  41. t.Run("Benchmark__Std_Json___Encode", Benchmark__Std_Json___Encode)
  42. t.Run("Benchmark__Gob________Encode", Benchmark__Gob________Encode)
  43. // t.Run("Benchmark__Std_Xml____Encode", Benchmark__Std_Xml____Encode)
  44. t.Run("Benchmark__JsonIter___Encode", Benchmark__JsonIter___Encode)
  45. t.Run("Benchmark__Bson_______Encode", Benchmark__Bson_______Encode)
  46. t.Run("Benchmark__Mgobson____Encode", Benchmark__Mgobson____Encode)
  47. t.Run("Benchmark__VMsgpack___Encode", Benchmark__VMsgpack___Encode)
  48. // t.Run("Benchmark__Gcbor______Encode", Benchmark__Gcbor______Encode)
  49. // t.Run("Benchmark__Xdr________Encode", Benchmark__Xdr________Encode)
  50. t.Run("Benchmark__Sereal_____Encode", Benchmark__Sereal_____Encode)
  51. benchmarkDivider()
  52. t.Run("Benchmark__Msgpack____Decode", Benchmark__Msgpack____Decode)
  53. t.Run("Benchmark__Binc_______Decode", Benchmark__Binc_______Decode)
  54. t.Run("Benchmark__Simple_____Decode", Benchmark__Simple_____Decode)
  55. t.Run("Benchmark__Cbor_______Decode", Benchmark__Cbor_______Decode)
  56. t.Run("Benchmark__Json_______Decode", Benchmark__Json_______Decode)
  57. t.Run("Benchmark__Std_Json___Decode", Benchmark__Std_Json___Decode)
  58. t.Run("Benchmark__Gob________Decode", Benchmark__Gob________Decode)
  59. // t.Run("Benchmark__Std_Xml____Decode", Benchmark__Std_Xml____Decode)
  60. t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode)
  61. t.Run("Benchmark__Bson_______Decode", Benchmark__Bson_______Decode)
  62. t.Run("Benchmark__Mgobson____Decode", Benchmark__Mgobson____Decode)
  63. // t.Run("Benchmark__VMsgpack___Decode", Benchmark__VMsgpack___Decode)
  64. // t.Run("Benchmark__Gcbor______Decode", Benchmark__Gcbor______Decode)
  65. // t.Run("Benchmark__Xdr________Decode", Benchmark__Xdr________Decode)
  66. // t.Run("Benchmark__Sereal_____Decode", Benchmark__Sereal_____Decode)
  67. }
  68. var benchmarkXSkipMsg = `>>>> Skipping - these cannot (en|de)code TestStruc - encode (gcbor, xdr, xml), decode (gcbor, vmsgpack, xdr, sereal, xml)`
  69. func BenchmarkXSuite(t *testing.B) {
  70. println(benchmarkXSkipMsg)
  71. benchmarkSuite(t, benchmarkXGroup)
  72. }
  73. func BenchmarkCodecXSuite(t *testing.B) {
  74. println(benchmarkXSkipMsg)
  75. benchmarkSuite(t, benchmarkCodecXGroup)
  76. }
  77. func benchmarkAllJsonEncodeGroup(t *testing.B) {
  78. benchmarkDivider()
  79. t.Run("Benchmark__Json_______Encode", Benchmark__Json_______Encode)
  80. t.Run("Benchmark__Std_Json___Encode", Benchmark__Std_Json___Encode)
  81. t.Run("Benchmark__JsonIter___Encode", Benchmark__JsonIter___Encode)
  82. }
  83. func benchmarkAllJsonDecodeGroup(t *testing.B) {
  84. benchmarkDivider()
  85. t.Run("Benchmark__Json_______Decode", Benchmark__Json_______Decode)
  86. t.Run("Benchmark__Std_Json___Decode", Benchmark__Std_Json___Decode)
  87. t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode)
  88. }
  89. func BenchmarkCodecVeryQuickAllJsonSuite(t *testing.B) {
  90. benchmarkVeryQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup)
  91. }
  92. func BenchmarkCodecQuickAllJsonSuite(t *testing.B) {
  93. benchmarkQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup)
  94. // benchmarkQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup)
  95. // benchmarkQuickSuite(t, "json-all", benchmarkAllJsonDecodeGroup)
  96. // depths := [...]int{1, 4}
  97. // for _, d := range depths {
  98. // benchmarkQuickSuite(t, d, benchmarkAllJsonEncodeGroup)
  99. // benchmarkQuickSuite(t, d, benchmarkAllJsonDecodeGroup)
  100. // }
  101. // benchmarkQuickSuite(t, 1, benchmarkAllJsonEncodeGroup)
  102. // benchmarkQuickSuite(t, 4, benchmarkAllJsonEncodeGroup)
  103. // benchmarkQuickSuite(t, 1, benchmarkAllJsonDecodeGroup)
  104. // benchmarkQuickSuite(t, 4, benchmarkAllJsonDecodeGroup)
  105. // benchmarkQuickSuite(t, 1, benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup)
  106. // benchmarkQuickSuite(t, 4, benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup)
  107. // benchmarkQuickSuite(t, benchmarkAllJsonEncodeGroup)
  108. // benchmarkQuickSuite(t, benchmarkAllJsonDecodeGroup)
  109. }