php 数组存储简单比较(json/serialize/igbinary/hprose)

环境

image.png

image.png

简单测试代码

测试结果

10000个数组元素

ini_set('memory_limit', '2048m');
$array = array_fill(0, 10000, rand(1, 9999));
run($array);

输出结果

JSON Encode: 0
JSON Decode: 0.003000020980835
Serialize: 0.0030009746551514
Unserialize: 0.0030009746551514
Igbinary  Serialize: 0.0010001659393311
Igbinary UnSerialize: 0.00099992752075195
Hprose Serialize: 0.34606909751892
Hprose Unserialize: 0.34206795692444

5000000个数组元素

ini_set('memory_limit', '2048m');
$array = array_fill(0, 5000000, rand(1, 9999));
run($array);

输出结果

JSON Encode: 0.96700000762939
JSON Decode: 1.6029999256134
Serialize: 10.430000066757
Unserialize: 10.762000083923
Igbinary  Serialize: 1.9860000610352
Igbinary UnSerialize: 0.8510000705719
Hprose Serialize: 138.22799992561
Hprose Unserialize: 170.71580314636



测试结果仅供参考(影响结果的因素有很多,~_~),一般不会遇到如此极端情况!

你可能感兴趣的:(php 数组存储简单比较(json/serialize/igbinary/hprose))