58

protobuf测试gofast

 4 years ago
source link: https://www.tuicool.com/articles/ANvuA3I
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

安装protoc

go get github.com/golang/protobuf/proto

goprotobuf

安装插件

go get github.com/golang/protobuf/protoc-gen-go

生成go文件

protoc --go_out=. *.proto

gogoprotobuf

安装插件

gogoprotobuf有两个插件可以使用

protoc-gen-gogo:和protoc-gen-go生成的文件差不多,性能也几乎一样(稍微快一点点)

protoc-gen-gofast:生成的文件更复杂,性能也更高(快5-7倍)

//gogo go get github.com/gogo/protobuf/protoc-gen-gogo //gofast go get github.com/gogo/protobuf/protoc-gen-gofast

安装gogoprotobuf库文件

go get github.com/gogo/protobuf/proto

go get github.com/gogo/protobuf/gogoproto //这个不装也没关系

生成go文件

//gogo protoc --gogo_out=. *.proto //gofast protoc --gofast_out=. *.proto 

性能测试

这里只是简单的用go test测试了一下

//goprotobuf

"编码":447ns/op  "解码":422ns/op

//gogoprotobuf-go

"编码":433ns/op"解码":427ns/op

//gogoprotobuf-fast

"编码":112ns/op"解码":112ns/op


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK