cprotobuf是用Cython实现的ProtocolBuffer协议。
性能测试结果:
$ ./setup.py build_ext --inplace$ cd benchmark$ ./bench.shencode[google official pure python]:10 loops, best of 3: 68.8 msec per loopencode[google official cpp python]:100 loops, best of 3: 19.4 msec per loopencode[py-protobuf][cprotobuf]:100 loops, best of 3: 3.58 msec per loopdecode[google official pure python]:10 loops, best of 3: 47.5 msec per loopdecode[google official cpp python]:100 loops, best of 3: 4.55 msec per loopdecode[py-protobuf][cprotobuf]:100 loops, best of 3: 3.98 msec per loop示例代码:
# coding: utf-8from cprotobuf import ProtoEntity, Field# file: person.protoclass Person(ProtoEntity): id = Field('int32', 1) name = Field('string', 2) email = Field('string', 3, required=False)# file: people.protoclass People(ProtoEntity): people = Field(Person, 1, repeated=True)
评论