Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using MsgPack, BenchmarkTools
  2.  
  3. struct MyType
  4. a::Vector{Symbol}
  5. b::Symbol
  6. c::Float64
  7. d::String
  8. e::UInt64
  9. f::Symbol
  10. g::Union{Nothing,Dict{Symbol,Any}}
  11. end
  12.  
  13. m = MyType([:a, :b, :c], :c, 13.4, "asdfasdfadf", 123498192384, :zst, nothing)
  14.  
  15. #####
  16. ##### master
  17. #####
  18.  
  19. mutable struct MutableMyType
  20. a::Vector{Symbol}
  21. b::Symbol
  22. c::Float64
  23. d::String
  24. e::UInt64
  25. f::Symbol
  26. g::Union{Nothing,Dict{Symbol,Any}}
  27. MutableMyType() = new()
  28. end
  29.  
  30. MsgPack.msgpack_type(::Type{MyType}) = MsgPack.ImmutableStructType()
  31. MsgPack.msgpack_type(::Type{MutableMyType}) = MsgPack.MutableStructType()
  32.  
  33. unpack_mutable(bytes) = MsgPack.unpack(bytes, Vector{MutableMyType})
  34. unpack_immutable(bytes) = MsgPack.unpack(bytes, Vector{MyType})
  35.  
  36. bytes = pack(fill(m, 10000))
  37.  
  38. @benchmark unpack_mutable($bytes) evals=1
  39. # BenchmarkTools.Trial:
  40. # memory estimate: 2.06 MiB
  41. # allocs estimate: 30003
  42. # --------------
  43. # minimum time: 13.091 ms (0.00% GC)
  44. # median time: 13.822 ms (0.00% GC)
  45. # mean time: 14.181 ms (1.92% GC)
  46. # maximum time: 57.976 ms (70.04% GC)
  47. # --------------
  48. # samples: 353
  49. # evals/sample: 1
  50.  
  51. @benchmark unpack_immutable($bytes) evals=1
  52. # BenchmarkTools.Trial:
  53. # memory estimate: 2.37 MiB
  54. # allocs estimate: 50003
  55. # --------------
  56. # minimum time: 5.988 ms (0.00% GC)
  57. # median time: 6.353 ms (0.00% GC)
  58. # mean time: 6.622 ms (3.23% GC)
  59. # maximum time: 46.284 ms (83.28% GC)
  60. # --------------
  61. # samples: 755
  62. # evals/sample: 1
  63.  
  64. #####
  65. ##### PR
  66. #####
  67.  
  68. MsgPack.msgpack_type(::Type{MyType}) = MsgPack.StructType()
  69.  
  70. unpack_strict(bytes) = MsgPack.unpack(bytes, Vector{MyType}; strict = (MyType,))
  71. unpack_nonstrict(bytes) = MsgPack.unpack(bytes, Vector{MyType})
  72.  
  73. bytes = pack(fill(m, 10000))
  74.  
  75. @benchmark unpack_strict($bytes) evals=1
  76. # BenchmarkTools.Trial:
  77. # memory estimate: 2.37 MiB
  78. # allocs estimate: 50005
  79. # --------------
  80. # minimum time: 6.076 ms (0.00% GC)
  81. # median time: 6.424 ms (0.00% GC)
  82. # mean time: 6.694 ms (3.12% GC)
  83. # maximum time: 46.050 ms (82.95% GC)
  84. # --------------
  85. # samples: 747
  86. # evals/sample: 1
  87.  
  88. @benchmark unpack_nonstrict($bytes) evals=1
  89. # BenchmarkTools.Trial:
  90. # memory estimate: 3.89 MiB
  91. # allocs estimate: 70003
  92. # --------------
  93. # minimum time: 16.324 ms (0.00% GC)
  94. # median time: 17.572 ms (0.00% GC)
  95. # mean time: 17.990 ms (2.27% GC)
  96. # maximum time: 59.383 ms (65.98% GC)
  97. # --------------
  98. # samples: 278
  99. # evals/sample: 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement