-
Notifications
You must be signed in to change notification settings - Fork 15
benchmarks
Anders Peter Fugmann edited this page Apr 16, 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 ~2x 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'.
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 │ mjWd/Run │ Prom/Run │ Percentage │
├────────────────────────────┼──────────┼─────────┼──────────┼──────────┼────────────┤
│ Enum/Deserialize/to_yojson │ 1.11ms │ 1.32Mw │ 100.58w │ 100.58w │ 20.42% │
│ Enum/Deserialize/to_json │ 5.45ms │ 1.02Mw │ 8.83w │ 8.83w │ 100.00% │
└────────────────────────────┴──────────┴─────────┴──────────┴──────────┴────────────┘
┌──────────────────────────┬──────────┬──────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├──────────────────────────┼──────────┼──────────┼──────────┼──────────┼────────────┤
│ Enum/Serialize/to_yojson │ 508.03us │ 330.04kw │ 18.89w │ 18.89w │ 100.00% │
│ Enum/Serialize/to_json │ 444.56us │ 330.07kw │ 9.26w │ 9.26w │ 87.51% │
└──────────────────────────┴──────────┴──────────┴──────────┴──────────┴────────────┘
┌─────────────────────────────┬────────────┬──────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├─────────────────────────────┼────────────┼──────────┼──────────┼──────────┼────────────┤
│ Tuple/Deserialize/to_yojson │ 325.83us │ 530.08kw │ 18.01w │ 18.01w │ 27.16% │
│ Tuple/Deserialize/to_json │ 1_199.74us │ 310.04kw │ 8.25w │ 8.25w │ 100.00% │
└─────────────────────────────┴────────────┴──────────┴──────────┴──────────┴────────────┘
┌───────────────────────────┬──────────┬──────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────────┼──────────┼──────────┼──────────┼──────────┼────────────┤
│ Tuple/Serialize/to_yojson │ 207.23us │ 330.12kw │ │ │ 35.64% │
│ Tuple/Serialize/to_json │ 581.42us │ 680.08kw │ 41.42w │ 41.42w │ 100.00% │
└───────────────────────────┴──────────┴──────────┴──────────┴──────────┴────────────┘
┌───────────────────────────────────────────┬────────────┬────────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────────────────────────┼────────────┼────────────┼──────────┼──────────┼────────────┤
│ Variant with record/Deserialize/to_yojson │ 732.42us │ 1_110.17kw │ 39.93w │ 39.93w │ 17.43% │
│ Variant with record/Deserialize/to_json │ 4_201.90us │ 830.11kw │ 68.73w │ 68.73w │ 100.00% │
└───────────────────────────────────────────┴────────────┴────────────┴──────────┴──────────┴────────────┘
┌─────────────────────────────────────────┬──────────┬──────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├─────────────────────────────────────────┼──────────┼──────────┼──────────┼──────────┼────────────┤
│ Variant with record/Serialize/to_yojson │ 419.12us │ 660.40kw │ │ │ 48.49% │
│ Variant with record/Serialize/to_json │ 864.40us │ 980.14kw │ 115.40w │ 115.40w │ 100.00% │
└─────────────────────────────────────────┴──────────┴──────────┴──────────┴──────────┴────────────┘
┌──────────────────────────────┬────────────┬────────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├──────────────────────────────┼────────────┼────────────┼──────────┼──────────┼────────────┤
│ Record/Deserialize/to_yojson │ 732.64us │ 1_110.17kw │ 39.92w │ 39.92w │ 20.80% │
│ Record/Deserialize/to_json │ 3_522.64us │ 760.09kw │ 69.68w │ 69.68w │ 100.00% │
└──────────────────────────────┴────────────┴────────────┴──────────┴──────────┴────────────┘
┌────────────────────────────┬──────────┬──────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├────────────────────────────┼──────────┼──────────┼──────────┼──────────┼────────────┤
│ Record/Serialize/to_yojson │ 326.64us │ 570.30kw │ │ │ 46.72% │
│ Record/Serialize/to_json │ 699.12us │ 820.11kw │ 87.55w │ 87.55w │ 100.00% │
└────────────────────────────┴──────────┴──────────┴──────────┴──────────┴────────────┘
┌─────────────────────────────────┬────────────┬──────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├─────────────────────────────────┼────────────┼──────────┼──────────┼──────────┼────────────┤
│ Test full/Deserialize/to_yojson │ 730.07ms │ 421.86Mw │ 8.53Mw │ 8.53Mw │ 37.36% │
│ Test full/Deserialize/to_json │ 1_954.20ms │ 260.17Mw │ 4.96Mw │ 4.96Mw │ 100.00% │
└─────────────────────────────────┴────────────┴──────────┴──────────┴──────────┴────────────┘
┌───────────────────────────────┬────────────┬──────────┬──────────┬──────────┬────────────┐
│ Name │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────────────┼────────────┼──────────┼──────────┼──────────┼────────────┤
│ Test full/Serialize/to_yojson │ 801.39ms │ 322.68Mw │ 22.11Mw │ 22.11Mw │ 77.85% │
│ Test full/Serialize/to_json │ 1_029.38ms │ 381.28Mw │ 25.36Mw │ 25.36Mw │ 100.00% │
└───────────────────────────────┴────────────┴──────────┴──────────┴──────────┴────────────┘