-
Notifications
You must be signed in to change notification settings - Fork 15
benchmarks
Anders Peter Fugmann edited this page Apr 17, 2019
·
4 revisions
Below is a table of tests which compare the ppx_protocol_dirver_json
to ppx_deriving_yojson
.
On large structures ppx_protocol_convis ~2-3x slower than
ppx_deriving_yojsonfor both serialization and de-serialization. This is mostly due to the extra in-directions made, as
ppx_protocol_conv` needs to call though a 'driver'. Still, numbers are in
Records and variants are significantly slower (x5) in deserilialization tests. I speculate that this is due to OCamls highly optimized pattern matching. Ppx_deriving_yojson
uses string pattern matches for de-serializing records and variants. As ppx_protocol_conv
allows full control of the serialized field names, it uses an hashtable to map field-names to constructors.
┌──────────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├──────────────────────────────┼──────────┼─────────┼────────────┤
│ Record/Deserialize/to_yojson │ 72.61ns │ 111.01w │ 20.08% │
│ Record/Deserialize/to_json │ 361.66ns │ 76.00w │ 100.00% │
└──────────────────────────────┴──────────┴─────────┴────────────┘
┌────────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├────────────────────────────┼──────────┼─────────┼────────────┤
│ Record/Serialize/to_yojson │ 32.16ns │ 57.02w │ 41.27% │
│ Record/Serialize/to_json │ 77.92ns │ 82.00w │ 100.00% │
└────────────────────────────┴──────────┴─────────┴────────────┘
┌─────────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├─────────────────────────────┼──────────┼─────────┼────────────┤
│ Tuple/Deserialize/to_yojson │ 34.87ns │ 53.00w │ 36.50% │
│ Tuple/Deserialize/to_json │ 95.54ns │ 8.00w │ 100.00% │
└─────────────────────────────┴──────────┴─────────┴────────────┘
┌───────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├───────────────────────────┼──────────┼─────────┼────────────┤
│ Tuple/Serialize/to_yojson │ 21.04ns │ 33.01w │ 44.86% │
│ Tuple/Serialize/to_json │ 46.90ns │ 33.00w │ 100.00% │
└───────────────────────────┴──────────┴─────────┴────────────┘
┌────────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├────────────────────────────┼──────────┼─────────┼────────────┤
│ Enum/Deserialize/to_yojson │ 119.38ns │ 132.01w │ 20.22% │
│ Enum/Deserialize/to_json │ 590.52ns │ 102.00w │ 100.00% │
└────────────────────────────┴──────────┴─────────┴────────────┘
┌──────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├──────────────────────────┼──────────┼─────────┼────────────┤
│ Enum/Serialize/to_yojson │ 51.97ns │ 33.00w │ 100.00% │
│ Enum/Serialize/to_json │ 42.55ns │ 33.00w │ 81.88% │
└──────────────────────────┴──────────┴─────────┴────────────┘
┌───────────────────────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├───────────────────────────────────────────┼──────────┼─────────┼────────────┤
│ Variant with record/Deserialize/to_yojson │ 73.79ns │ 111.01w │ 17.68% │
│ Variant with record/Deserialize/to_json │ 417.37ns │ 83.00w │ 100.00% │
└───────────────────────────────────────────┴──────────┴─────────┴────────────┘
┌─────────────────────────────────────────┬──────────┬─────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ Percentage │
├─────────────────────────────────────────┼──────────┼─────────┼────────────┤
│ Variant with record/Serialize/to_yojson │ 37.86ns │ 66.03w │ 43.01% │
│ Variant with record/Serialize/to_json │ 88.02ns │ 98.00w │ 100.00% │
└─────────────────────────────────────────┴──────────┴─────────┴────────────┘
┌─────────────────────────────────┬──────────┬─────────┬───────────┬───────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├─────────────────────────────────┼──────────┼─────────┼───────────┼───────────┼────────────┤
│ Test full/Deserialize/to_yojson │ 115.94us │ 59.53kw │ 1_721.10w │ 1_721.10w │ 50.96% │
│ Test full/Deserialize/to_json │ 227.53us │ 29.46kw │ 748.62w │ 748.62w │ 100.00% │
└─────────────────────────────────┴──────────┴─────────┴───────────┴───────────┴────────────┘
┌───────────────────────────────┬──────────┬─────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────────────┼──────────┼─────────┼──────────┼──────────┼────────────┤
│ Test full/Serialize/to_yojson │ 110.55us │ 38.75kw │ 3.01kw │ 3.01kw │ 87.28% │
│ Test full/Serialize/to_json │ 126.67us │ 41.46kw │ 3.23kw │ 3.23kw │ 100.00% │
└───────────────────────────────┴──────────┴─────────┴──────────┴──────────┴────────────┘