Baldur Bjarnason on Nostr: Doing a bit of benchmarking for a project to get a sense of the various different ...
Doing a bit of benchmarking for a project to get a sense of the various different approaches available in JS for serialising objects to buffers and the surprising bit is just how fast browser-native encoder.encode(JSON.stringify(data)) really is
The cbor or msgpack serialisers were usually 200-1000% slower. The only one that came within a spitting distance of native JSON serialisation was cbor-x and that's 30kB minified
Though the difference is probably not noticeable for small (<5kB) objects
Published at
2024-09-11 15:54:40Event JSON
{
"id": "fca2f8ec5475ed1772e2245b927cefac8d1a0edbe095e2b951f19038862f0ad6",
"pubkey": "11f94b00429b537972e1e4b4858c9a4226382961ef5995e3b77ff20bf92899d3",
"created_at": 1726070080,
"kind": 1,
"tags": [
[
"proxy",
"https://toot.cafe/users/baldur/statuses/113119728762893956",
"activitypub"
]
],
"content": "Doing a bit of benchmarking for a project to get a sense of the various different approaches available in JS for serialising objects to buffers and the surprising bit is just how fast browser-native encoder.encode(JSON.stringify(data)) really is\n\nThe cbor or msgpack serialisers were usually 200-1000% slower. The only one that came within a spitting distance of native JSON serialisation was cbor-x and that's 30kB minified\n\nThough the difference is probably not noticeable for small (\u003c5kB) objects",
"sig": "1b252d60a6440043a5629101f34fad2e991e49da61e4d98b6b378894ba4f383de97f2f41e126dc69da65b5359fb8d010820865937843ce00045fd8ac1931c727"
}