pyList

go json 解析速度测试

go json 解析速度测试

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)
	}))
	
	
}
本文标签: golang goexample json encoding
相关推荐
本文网址: https://pylist.com/t/1435051135 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
发表第一条评论!
验证码图片