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