redis not open [StoreAllChain] time cost = 1.275416ms redis not open [StoreAllChain] time cost = 1.040458ms [TestProtoSpeed] time cost = 6.619953912s
Redis open [StoreAllChain] time cost = 1.471769ms [StoreAllChain] time cost = 1.158825ms [StoreAllChain] time cost = 1.081494ms [TestProtoSpeed] time cost = 7.785562597s
删除其它日志 [TestProtoSpeed] time cost = 7.827823686s --- PASS: TestProtoSpeed (7.83s)
10000次,json 对比
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
redis not open [StoreAllChain] time cost = 2.838655ms redis not open [StoreAllChain] time cost = 2.539433ms redis not open [StoreAllChain] time cost = 2.775757ms [TestJsonSpeed] time cost = 12.611491383s
Redis open [StoreAllChain] time cost = 2.643816ms [StoreAllChain] time cost = 3.363096ms [StoreAllChain] time cost = 2.989628ms [StoreAllChain] time cost = 2.51413ms [TestJsonSpeed] time cost = 16.264468555s
删除其它日志 [TestJsonSpeed] time cost = 17.868695349s --- PASS: TestJsonSpeed (17.88s)
测试平均结果
10000
20000
Protobuf
7
24
Json
16
61
结论
protobuf 在 go 上的表现和其原始并没有量级的差距,但还是好过 go 原生 json 解析不少。其跨语言跨平台的特性和高效还是值得一试的。