这里是使用Golang json 标准库对一个简单的 struct
作解析速度测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"encoding/json"
. "testing"
)
type OneField struct {
A int
}
type ManyFields struct{
A int
B string
C int32
D *OneField
}
func main() {
fmt.Println("Hello, playground")
smallStruct := OneField{}
fmt.Println(AllocsPerRun(10000, func(){
json.Marshal(smallStruct)
}))
largeStruct := ManyFields{}
fmt.Println(AllocsPerRun(10000, func(){
json.Marshal(largeStruct)
}))
fmt.Println(AllocsPerRun(10000, func(){
json.Marshal("hello")
}))
simpleMap := map[string]interface{}{"name": "name", "mail": "mail"}
fmt.Println(AllocsPerRun(10000, func(){
json.Marshal(simpleMap)
}))
}
输出:
1
2
3
4
5
Hello, playground
1
2
1
11
本文网址: https://pylist.com/topic/102.html 转摘请注明来源