-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有篇文章说“在Go1.10以后性能与标准库差异不大,这个第三方库的意义已经不大了”,是真的吗?有大佬说一下吗? #333
Comments
你看我提的issues,用json-iterator替换标准库的jsonrpc 性能对比就知道了,这个库在go1.10环境下好像比标准库性能差的多了去了。。。。。 |
怕它在生产环境搞事情,还是用回标准库把,标准库牛逼 |
那篇文章没有说清楚,我大概看完了json-iterator的实现.主要优化除了文章里面说的缓存序列化过的结构体以外.还有大量的内存对象池化,减少GC损耗.说白了就是要明确定义字段的结构体. |
能跑就行了,要啥自行车 |
此库等1.13正式版 可能 要打包了。没什么任何优势了, 目前在golang 1.12.4
|
即使“性能与标准库差异不大”,这个库还是挺有意义的。 |
多看看别人的源码, 多学习下设计思想, 用不用还是看自己 |
注意,我没用jsoniter.ConfigCompatibleWithStandardLibrary其实在golang 12里面,marshal map 的时候还是有性能优势的。 package main
import (
'encoding/json'
jsoniter 'github.com/json-iterator/go'
'testing'
)
type Car struct {
Name string
Name1 string
Name2 string
Name3 string
}
var (
c = Car{Name1: 'xxxxxxxxxxxxx', Name2: 'xxxxxxxxxxxxxxxxxxxx', Name3: 'xxxxxxxxxxxxxxxxxx', Name: 'buickxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
mymap = map[string]string{
'Name1': 'xxxxxxxxxxxxx',
'Name2': 'xxxxxxxxxxxxxxxxxxxx',
'Name3': 'xxxxxxxxxxxxxxxxxx',
'Name': 'buickxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}
mymap2 = map[string]interface{}{
'Name1': 'xxxxxxxxxxxxx',
'Name2': 'xxxxxxxxxxxxxxxxxxxx',
'Name3': 'xxxxxxxxxxxxxxxxxx',
'Name': 'buickxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}
)
func BenchmarkStructJsoniter(b *testing.B) {
for i := 0; i < b.N; i++ { //use b.N for looping
jsoniter.Marshal(&c)
}
}
func BenchmarkStructStd(b *testing.B) {
c := Car{Name1: 'xxxxxxxxxxxxx', Name2: 'xxxxxxxxxxxxxxxxxxxx', Name3: 'xxxxxxxxxxxxxxxxxx', Name: 'buickxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
for i := 0; i < b.N; i++ { //use b.N for looping
json.Marshal(&c)
}
}
func BenchmarkMapJsoniter(b *testing.B) {
for i := 0; i < b.N; i++ { //use b.N for looping
jsoniter.Marshal(mymap)
}
}
func BenchmarkMapStd(b *testing.B) {
for i := 0; i < b.N; i++ { //use b.N for looping
json.Marshal(mymap)
}
}
func BenchmarkMapJsoniter2(b *testing.B) {
for i := 0; i < b.N; i++ { //use b.N for looping
jsoniter.Marshal(mymap2)
}
}
func BenchmarkMapStd2(b *testing.B) {
for i := 0; i < b.N; i++ { //use b.N for looping
json.Marshal(mymap2)
}
} 测试结果: go version go1.12.13 linux/amd64
|
这里有篇文章说“在Go1.10以后性能与标准库差异不大,这个第三方库的意义已经不大了”,是真的吗?有大佬说一下吗?
http://vearne.cc/archives/433
The text was updated successfully, but these errors were encountered: