commitstore/bench-serialize: add benchmark for mincode

Summary:
Add benchmark for the newly added mincode serialization. An example run shows:

  serialize   by cbor                                32.573 ms   9.701 MB
  deserialize by cbor                                79.471 ms
  serialize   by cbor-packed                         28.574 ms   7.801 MB
  deserialize by cbor-packed                         73.337 ms
  serialize   by bincode                             25.175 ms   6.789 MB
  deserialize by bincode                             23.193 ms
  serialize   by mincode                             19.687 ms   5.389 MB
  deserialize by mincode                             24.852 ms
  serialize   by handwritten                          2.939 ms   5.389 MB
  deserialize by handwritten                          7.963 ms
  serialize   by abomonation                          1.752 ms  10.389 MB
  deserialize by abomonation                          6.060 ms

Interesting facts:
- mincode serialization is actually faster than bincode. (it would appear
  slower if vec was not preallocated).
- mincode is much slower than handwritten. This is partially caused by serde
  not having a native "fixed array" type so it cannot do `write_all(&[u8; 20])`
  but has to `write_u8(x)` 20 times (which translates to
  `Vec::extend_from_slice` 20 times.

Regardless, the main reason I think mincode is compelling is its compactness
and relatively good performance. Although handwritten is the fastest, the
mincode performance is fine in the commit storage usecase, since mincode is
probably not the bottleneck.

Reviewed By: kulshrax

Differential Revision: D17087352

fbshipit-source-id: 820ff8538d3ab9ebef2eda0a40cad126e26db622
This commit is contained in:
Jun Wu 2019-09-06 13:10:33 -07:00 committed by Facebook Github Bot
parent 3f459fc3ef
commit 0cc8f5ce84
2 changed files with 7 additions and 0 deletions

View File

@ -7,6 +7,7 @@ edition = "2018"
abomonation = "*"
abomonation_derive = "*"
bincode = "*"
mincode = { path = "../../mincode" }
minibench = { path = "../../minibench" }
rmp = "*"
rmp-serde = "*"

View File

@ -95,6 +95,12 @@ fn main() {
|d| bincode::deserialize(d).unwrap(),
);
bench_algorithm(
"mincode",
|c, w| mincode::serialize_into(w, c).unwrap(),
|d| mincode::deserialize(d).unwrap(),
);
bench_algorithm(
"handwritten",
|c, w| handwritten::encode(w, c),