Created
June 21, 2020 15:48
-
-
Save akoutmos/15b61ab11e75670f2c5b661106258feb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------- Setup test data ---------------- | |
small_map_as_term = %{ | |
some: "value", | |
another: "key", | |
some_list: [1, 2, 3, 4, 5], | |
nil_value: nil | |
} | |
big_map_as_term = %{ | |
payload: [ | |
false, | |
%{ | |
"anyone" => "nine", | |
"basis" => -1_736_842_260.3915267, | |
"find" => "personal", | |
"ground" => 632_672_126.6082387, | |
"indicate" => -153_373_541, | |
"position" => "string", | |
"smaller" => %{ | |
"bowl" => "anywhere", | |
"compass" => -526_743_549.8039379, | |
"could" => -1_820_388_929.50489, | |
"dug" => %{ | |
"arrangement" => [ | |
false, | |
"cool", | |
280_895_474, | |
false, | |
754_832_901.7025824, | |
false, | |
false, | |
"stronger", | |
false | |
], | |
"captured" => -485_915_421, | |
"effect" => "giant", | |
"forty" => true, | |
"hall" => false, | |
"please" => true, | |
"source" => "stage", | |
"stand" => true, | |
"wolf" => "before" | |
}, | |
"gravity" => "gone", | |
"minute" => false, | |
"neighborhood" => 1_945_004_217.1266694, | |
"someone" => "thing", | |
"spring" => "hollow" | |
}, | |
"system" => 1_222_337_063, | |
"won" => false | |
}, | |
true, | |
-1_834_992_102, | |
false, | |
107_528_114, | |
"softly", | |
1_731_794_762, | |
-28_063_035 | |
] | |
} | |
small_map_as_binary = :erlang.term_to_binary(small_map_as_term) | |
big_map_as_binary = :erlang.term_to_binary(big_map_as_term) | |
small_map_as_json = Jason.encode!(small_map_as_term) | |
big_map_as_json = Jason.encode!(big_map_as_term) | |
# Serialization and Deserialization tests | |
tests = %{ | |
# Small Map | |
"Deserialize Small Binary -> Term" => fn -> :erlang.binary_to_term(small_map_as_binary) end, | |
"Deserialize Small JSON -> Term" => fn -> Jason.decode!(small_map_as_json) end, | |
# "Serialize Small Term -> Binary" => fn -> :erlang.term_to_binary(small_map_as_term) end, | |
# "Serialize Small Term -> JSON" => fn -> Jason.encode!(small_map_as_term) end, | |
# Large Map | |
"Deserialize Large Binary -> Term" => fn -> :erlang.binary_to_term(big_map_as_binary) end, | |
"Deserialize Large JSON -> Term" => fn -> Jason.decode!(big_map_as_json) end | |
# "Serialize Large Term -> Binary" => fn -> :erlang.term_to_binary(big_map_as_term) end, | |
# "Serialize Large Term -> JSON" => fn -> Jason.encode!(big_map_as_term) end | |
} | |
Benchee.run( | |
tests, | |
warmup: 2, | |
time: 5 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Deserializing
Name ips average deviation median 99th %
Deserialize Small Binary -> Term 2166.92 K 0.46 μs ±4299.00% 0.42 μs 0.88 μs
Deserialize Large Binary -> Term 482.43 K 2.07 μs ±643.74% 1.92 μs 4.01 μs
Deserialize Small JSON -> Term 478.17 K 2.09 μs ±837.89% 1.84 μs 3.69 μs
Deserialize Large JSON -> Term 64.59 K 15.48 μs ±19.03% 15.06 μs 24.68 μs
Comparison:
Deserialize Small Binary -> Term 2166.92 K
Deserialize Large Binary -> Term 482.43 K - 4.49x slower +1.61 μs
Deserialize Small JSON -> Term 478.17 K - 4.53x slower +1.63 μs
Deserialize Large JSON -> Term 64.59 K - 33.55x slower +15.02 μs
Serializing
Name ips average deviation median 99th %
Serialize Small Term -> Binary 669.42 M 0.00149 μs ±17325.18% 0 μs 0.0340 μs
Serialize Large Term -> Binary 667.39 M 0.00150 μs ±8576.77% 0 μs 0.0310 μs
Serialize Small Term -> JSON 0.56 M 1.78 μs ±1284.47% 1.45 μs 3.79 μs
Serialize Large Term -> JSON 0.0523 M 19.11 μs ±89.19% 18.20 μs 32.67 μs
Comparison:
Serialize Small Term -> Binary 669.42 M
Serialize Large Term -> Binary 667.39 M - 1.00x slower +0.00000 μs
Serialize Small Term -> JSON 0.56 M - 1192.90x slower +1.78 μs
Serialize Large Term -> JSON 0.0523 M - 12791.81x slower +19.11 μs