Skip to content

benchmarks

Anders Peter Fugmann edited this page Apr 17, 2019 · 4 revisions

Benchmarks

Below is a table comparing ppx_protocol_driver_json to ppx_deriving_yojson. On large structures ppx_protocol_conv is ~2x slower than ppx_deriving_yojson for 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 string 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 and constructor/variant names.

Below is the output from make bench.

Name Time/Run mWd/Run mjWd/Run Prom/Run Percentage
Record/Deserialize/to_yojson 72.33ns 111.01w 0.00w 0.00w 20.68%
Record/Deserialize/to_json 349.74ns 76.00w 0.01w 0.01w 100.00%
Record/Serialize/to_yojson 31.51ns 57.02w 6.96e-6w 6.96e-6w 42.64%
Record/Serialize/to_json 73.92ns 82.00w 0.01w 0.01w 100.00%
Tuple/Deserialize/to_yojson 34.63ns 53.00w 0.00w 0.00w 36.18%
Tuple/Deserialize/to_json 95.71ns 8.00w 33.69e-6w 33.69e-6w 100.00%
Tuple/Serialize/to_yojson 20.91ns 33.01w 4.97e-6w 4.97e-6w 45.99%
Tuple/Serialize/to_json 45.46ns 33.00w 0.00w 0.00w 100.00%
Enum/Deserialize/to_yojson 116.08ns 132.01w 0.01w 0.01w 21.74%
Enum/Deserialize/to_json 534.05ns 102.00w 914.26e-6w 914.26e-6w 100.00%
Enum/Serialize/to_yojson 51.66ns 33.00w 0.00w 0.00w 100.00%
Enum/Serialize/to_json 41.52ns 33.00w 949.18e-6w 949.18e-6w 80.38%
Variant with record/Deserialize/to_yojson 74.98ns 111.01w 0.00w 0.00w 18.15%
Variant with record/Deserialize/to_json 413.11ns 83.00w 0.01w 0.01w 100.00%
Variant with record/Serialize/to_yojson 35.72ns 66.03w 7.69e-6w 7.69e-6w 40.04%
Variant with record/Serialize/to_json 89.21ns 98.00w 0.01w 0.01w 100.00%
Test full/Deserialize/to_yojson 83.60us 52.40kw 958.40w 958.40w 44.04%
Test full/Deserialize/to_json 189.83us 24.91kw 537.15w 537.15w 100.00%
Test full/Serialize/to_yojson 83.15us 32.80kw 2.13kw 2.13kw 81.06%
Test full/Serialize/to_json 102.58us 35.52kw 2.44kw 2.44kw 100.00%
Clone this wiki locally