Skip to content

mustiikhalil/benchmarks-flexbuffers

Repository files navigation

[WIP] Benchmarks for FlexBuffers Swift

⚠️⚠️ WIP

  • The vision for the future is to add some type of Codable protocol to make it easier for users to write flexbuffers

Introduction

The following Repository compares the benchmarks between the native swift JSON encoder and decode compared to the FlexBuffers implementation. The vision of flexbuffers API within swift is to be something similar to this:

struct Position: FlexBufferCodable { let x, y, z: Double }

let a = Position(x: 3.0, y: 4.0, z: 5.0)

let buffer: ByteBuffer = FlexBufferCoder().encode(a)

let pos = FlexBufferCoder().decode(buffer, as: Position.self)

Size comparison

Within the resources folder you would find the binaries and jsons

Keys Twitter Canada
JSON 617K 2.1M
FlatBuffer 111K 878K
FlexBuffer shared key 136K 1.3M
FlexBuffer shared key and string 93K 1.3M

Notes

  • Canada test is using a typedvector (swift native arrays) to achive that performance

Readable Benchmarks

swift package benchmark --grouping metric --time-units nanoseconds

Host 'Mustiis-MacBook-Pro.local' with 12 'arm64' processors with 24 GB memory, running:
Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041

Throughput (# / s)
╒════════════════════════════════════════════════════════════════════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╕
│ Test                                                                   │        p0 │       p25 │       p50 │       p75 │       p90 │       p99 │      p100 │   Samples │
╞════════════════════════════════════════════════════════════════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡
│ Benchmarks:canada-decode-Flatbuffer (M)                                │       353 │       334 │       329 │       304 │       296 │       282 │         0 │    655761 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-FlatbufferMutable (M)                         │       600 │       546 │       534 │       500 │       480 │       462 │        23 │    932607 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-JSON (K)                                      │        67 │        65 │        65 │        64 │        63 │        63 │        63 │       194 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-manual-FlexbufferSharedKeys (M)               │       632 │       600 │       572 │       534 │       522 │       500 │        16 │    973746 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-manual-FlexbufferSharedKeysAndStrings (M)     │       632 │       600 │       572 │       534 │       522 │       511 │        46 │    968817 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-Flatbuffer (K)                                │      4237 │      4067 │      3931 │      3825 │      3765 │      3671 │      2771 │     11745 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-JSON (K)                                      │        36 │        35 │        35 │        34 │        34 │        34 │        33 │       104 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-manual-FlexbufferSharedKeys (K)               │       341 │       312 │       308 │       306 │       302 │       292 │       275 │       926 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-manual-FlexbufferSharedKeysAndStrings (K)     │       336 │       308 │       305 │       298 │       291 │       281 │       257 │       909 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-Flatbuffer (M)                               │      3003 │      2398 │      2185 │      2179 │      2001 │      1849 │        40 │   1668456 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-JSON (K)                                     │       672 │       628 │       620 │       615 │       609 │       572 │       545 │      1861 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-manual-FlexbufferSharedKeys (M)              │      2183 │      1716 │      1601 │      1601 │      1502 │      1413 │        49 │   1511991 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-manual-FlexbufferSharedKeysAndStrings (M)    │      2183 │      1845 │      1716 │      1601 │      1601 │      1500 │        50 │   1572550 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-Flatbuffer (M)                               │        18 │        17 │        16 │        16 │        16 │        15 │        10 │     47233 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-JSON (K)                                     │      1490 │      1415 │      1388 │      1362 │      1341 │      1317 │      1187 │      4155 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeys (K)              │      3317 │      3151 │      3103 │      3039 │      2987 │      2911 │      2511 │      9259 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeysAndStrings (K)    │      1612 │      1528 │      1507 │      1493 │      1478 │      1446 │      1254 │      4525 │
╘════════════════════════════════════════════════════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛

Time (total CPU)
╒════════════════════════════════════════════════════════════════════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╕
│ Test                                                                   │        p0 │       p25 │       p50 │       p75 │       p90 │       p99 │      p100 │   Samples │
╞════════════════════════════════════════════════════════════════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡
│ Benchmarks:canada-decode-Flatbuffer (ns) *                             │         3 │         3 │         4 │         4 │         4 │         4 │        34 │    655761 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-FlatbufferMutable (ns) *                      │         2 │         2 │         2 │         3 │         3 │         3 │        61 │    932607 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-JSON (ns) *                                   │     14833 │     15409 │     15483 │     15589 │     15753 │     15924 │     15924 │       194 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-manual-FlexbufferSharedKeys (ns) *            │         2 │         2 │         2 │         2 │         2 │         3 │        48 │    973746 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-decode-manual-FlexbufferSharedKeysAndStrings (ns) *  │         2 │         2 │         2 │         2 │         2 │         3 │        20 │    968817 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-Flatbuffer (ns) *                             │       236 │       247 │       255 │       262 │       266 │       273 │       346 │     11745 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-JSON (ns) *                                   │     28018 │     28656 │     28836 │     29131 │     29344 │     29524 │     30167 │       104 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-manual-FlexbufferSharedKeys (ns) *            │      2932 │      3207 │      3244 │      3271 │      3318 │      3430 │      3634 │       926 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:canada-encode-manual-FlexbufferSharedKeysAndStrings (ns) *  │      2977 │      3248 │      3279 │      3363 │      3432 │      3541 │      3867 │       909 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-Flatbuffer (ns) *                            │         1 │         1 │         1 │         1 │         1 │         1 │        18 │   1668456 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-JSON (ns) *                                  │      1488 │      1593 │      1615 │      1628 │      1642 │      1748 │      1835 │      1861 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-manual-FlexbufferSharedKeys (ns) *           │         1 │         1 │         1 │         1 │         1 │         1 │        21 │   1511991 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-decode-manual-FlexbufferSharedKeysAndStrings (ns) * │         1 │         1 │         1 │         1 │         1 │         1 │        26 │   1572550 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-Flatbuffer (ns) *                            │        56 │        60 │        64 │        64 │        65 │        69 │        98 │     47233 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-JSON (ns) *                                  │       672 │       708 │       721 │       735 │       746 │       759 │       827 │      4155 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeys (ns) *           │       302 │       318 │       323 │       330 │       336 │       344 │       399 │      9259 │
├────────────────────────────────────────────────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Benchmarks:twitter-encode-manual-FlexbufferSharedKeysAndStrings (ns) * │       621 │       655 │       664 │       671 │       677 │       692 │       783 │      4525 │
╘════════════════════════════════════════════════════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published