Created
March 31, 2011 11:29
-
-
Save jedisct1/896204 to your computer and use it in GitHub Desktop.
msgpack vs json vs igbinary vs php serialize
This file contains 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
* Results | |
ruby json: 19,777,781 bytes | |
ruby msgpack: 14,757,439 bytes | |
php serialize(): 33,777,792 bytes | |
php igbinary: 18,757,571 bytes | |
php json_encode: 19,777,781 bytes | |
msgpack vs json (MRI 1.9.2) speed: | |
user system total real | |
msgpack: | |
0.900000 0.040000 0.940000 ( 1.171771) | |
json: | |
1.880000 0.130000 2.010000 ( 2.172833) | |
* Source | |
Ruby: | |
require 'msgpack' | |
require 'json' | |
require 'benchmark' | |
a = (0...1_000_000).group_by { |i| "k-#{i}" } | |
Benchmark.bm do |x| | |
x.report("msgpack:") { puts "size=" + MessagePack.pack(a).length.to_s } | |
x.report("json:") { puts "size=" + a.to_json.length.to_s } | |
end | |
PHP: | |
ini_alter('memory_limit', -1); | |
$a = array(); | |
for ($i = 0; $i < 1000000; $i++) { | |
$a["k-$i"] = array($i); | |
} | |
echo 'serialize()d size=' . strlen(serialize($a)) . "\n"; | |
echo 'igbinary_serialize()d size=' . strlen(igbinary_serialize($a)) . "\n"; | |
echo 'json_encode()d size=' . strlen(json_encode($a)) . "\n"; | |
I did some benchmark in PHP (I know it is an old gist but it is the first on Google Search)
https://github.com/EFTEC/php-benchmarks#serializations
Conclusion: I am impressed with igbinary. 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
10+ years later, msgpack is over 50% smaller than php serialize (and best in the league too).
PHP Version 7.2.24-0ubuntu0.18.04.6
msgpack version: 2.0.3
igbinary version: 2.0.8
json version: 1.6.0
Results:
Added elapsed time in microseconds - json serialize is way faster)