cprotobuf基于 cython 的協(xié)議緩沖區(qū)
cprotobuf 是用 Cython 實現(xiàn)的 Protocol Buffer 協(xié)議。
性能測試結(jié)果:
$ ./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)評論
圖片
表情
