FlatBuffers与protobuf性能比较
2024-07-09 12:24:04 224人阅读
FlatBuffers发布时,顺便也公布了它的性能数据,具体数据请见Benchmark。
它的测试用例由以下数据构成"a set of about 10 objects containing an array, 4 strings, and a large variety of int/float scalar values of all sizes, meant to be representative of game data, e.g. a scene format."
我感觉这样测试如同儿戏,便自己设计了一个测试用例,主要关注CPU计算时间和内存空间占用两个指标,参考对象是protobuf。
测试用例为:序列化一个通讯录personal_info_list(table),通讯录可以认为是有每个人的信息(personal_info)的集合。每个人信息personal_info(table)有:个人id(uint)、名字(string)、年龄(byte)、性别(enum, byte)和电话号码(ulong)。本来我想用struct表示personal_info(table),但是struct不允许有数组或string成员,无奈我用table描述它了。相应的idl文件如下:
11
enum
GENDER_TYPE : byte
27
table personal_info_list
29
info : [personal_info];
32
root_type personal_info_list;
因为要以protobuf做性能参考,列出protobuf的idl文件如下:
20
optional uint32 id = 1;
21
optional string name = 2;
22
optional uint32 age = 3;
23
optional gender_type gender = 4;
24
optional uint64 phone_num = 5;
27
message personal_info_list
29
repeated personal_info info = 1;
在内存中构造37个personal_info对象,并序列化之,重复这个过程100万次。
测试结果如下:
01
测试环境:12Core Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz
03
total used free shared buffers cached
04
Mem: 66081944 65831100 250844 0 182240 46903452
05
-/+ buffers/cache: 18745408 47336536
06
Swap: 975864 724648 251216
10
loop = 1000000, time diff = 14283ms
14
loop = 1000000, time diff = 14096ms
18
loop = 1000000, time diff = 14229ms
20
占用内存空间841Byte,平均运算时间42608ms / 3 = 14202.7ms
24
loop = 1000000, time diff = 11694ms
28
loop = 1000000, time diff = 11710ms
32
loop = 1000000, time diff = 11774ms
34
占用内存空间1712Byte,平均运算时间35178ms / 3 = 11726ms
37
测试环境:1 Core Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
39
total used free shared buffers cached
40
Mem: 753932 432672 321260 0 89236 258052
41
-/+ buffers/cache: 85384 668548
42
Swap: 1324028 0 1324028
46
loop = 1000000, time diff = 12779ms
50
loop = 1000000, time diff = 13475ms
54
loop = 1000000, time diff = 12604ms
56
占用内存空间841Byte,平均运算时间38858ms / 3 = 12952.7ms
60
loop = 1000000, time diff = 9424ms
64
loop = 1000000, time diff = 9277ms
68
loop = 1000000, time diff = 9265ms
70
info vecotor size:37, its right size:37
71
占用内存空间1712Byte,平均运算时间28036ms / 3 = 9345ms
从以上数据看出,在内存空间占用这个指标上,FlatBuffers占用的内存空间比protobuf多了两倍,而二者的cpu计算时间虽然相差3000ms左右,但考虑到测试用了100万次,二者每次计算时间几乎没有差别。
从以上测试数据来看,FlatBuffers的性能并不如它吹嘘的那么好。个人稍有点失望。
测试程序已经上传到百度网盘,点击这个链接即可下载。欢迎各位的批评意见。
des style class code http
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。
×
https://www.u72.net/daima/b922.html