# Benchmarking FlatBuffers and ProtocolBuffers Inspired by repo made by kcchu: https://github.com/kcchu/buffer-benchmarks Benchmark script from pfh: https://github.com/pfletcherhill/farcaster-hub/blob/serialization-benchmarks/apps/benchmark/src/index.ts ### Step 1: Generate test data Generate 100 objects that represent deserialized CastAdd messages. Each has a 200 char text, two embeded URLs, two fid mentions, and a parent cast. ### Step 2: Encode test data for 15s For 15s, randomly pick one of the test objects and serialize it using the given framework (flatbuffers or protobufs). Record the number of messages encoded and the total size (in bytes) of the encoded messages. ### Step 3: Decode for 15s For 15s, repeatedly decode the last encoded CastAdd message using the same serialization framework and read the hash, fid, and text from it. Record the number of messages decoded. ### Results | Test | Flatbuffers | Protobufs | | -------- | -------- | -------- | | Encoding time | 14.9 s | 14.6 s | | Encoded count | 996855 | 5301473 (+431%) | | ms / encoding | 0.01496 ms | 0.00275 ms (-81.62%)| | Mean message size (bytes) | 649 | 444 (-31.67%) | | Decoding time | 14.5 s | 14.6 s | | Decoded count | 7159356 | 6698296 (-6.44%) | | ms / decoding | 0.00212 ms | 0.00217 ms (+2.36%) | ### Memory profiling During the encode and decode steps, the script also takes a snapshot of the nodejs memory usage. ![](https://i.imgur.com/gBink11.png) ![](https://i.imgur.com/Si0WhDC.png) Spreadsheet with memory profiling: https://docs.google.com/spreadsheets/d/17BSvPx2jwTLgU7cyhaEYUKmi8DDD7xX4FGzj3hMqh_k/edit?usp=sharing