Skip to content

Instantly share code, notes, and snippets.

@aprius
Created February 4, 2020 07:01
Show Gist options
  • Select an option

  • Save aprius/f611e59afdc039bdd99b1ec3e2c18f57 to your computer and use it in GitHub Desktop.

Select an option

Save aprius/f611e59afdc039bdd99b1ec3e2c18f57 to your computer and use it in GitHub Desktop.
FlatBuffer vs MessagePack-Csharp vs JsonUtility

Brenchmark

  • Serialize and Deserialize array 2000 item
Type Size Deserialize Deserialize GC Serialize Serialize GC
FlatBuffer binary 2.846 0.0528 0.2485 0.2745 0.7279
MessagePack-Csharp binary 1.000 1.0000 1.0000 1.0000 1.0000
JsonUtility text 2.657 0.0793 0.6279 0.0341 0.3851
  • Searching item MemoryMaster is faster than FlatBuffer

  • find item have id 1746 in array 2000 item

var item = Find($"Id_1746");
Find Find GC
FlatBuffer 1.76ms 335B
MemoryMaster 0.7ms 48B
  • find each item once in array
for (int i = 1; i < 2000; i++)
{
    var item = Find($"Id_{i}");
}
Find Find GC
FlatBuffer 34.4ms 254.5KB
MemoryMaster 4.17ms 179.2KB
  • JsonUtility has many limits as:
    • not support array (you need write class helper to support this)
    • not support dictionary (you need custom class which acts as a dictionary item or using other custom serializer)
    • the float value serialize is not accurate due to the encoding problem. You can change float to string to get an accurate value.
    • not support binnay search as part of itself
@aprius
Copy link
Copy Markdown
Author

aprius commented Dec 19, 2022

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment