14 Star 51 Fork 12

Hprose / hprose-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
register_map_encoder.go 641 Bytes
一键复制 编辑 原始数据 按行查看 历史
Hprose 提交于 2016-10-31 21:45 . Update to hprose 2.0
package main
import (
"fmt"
"math"
"time"
"github.com/hprose/hprose-golang/io"
)
func stringFloat64MapEncoder(w *io.Writer, v interface{}) {
m := v.(map[string]float64)
for key, val := range m {
w.WriteString(key)
w.WriteFloat(val, 64)
}
}
func test(m map[string]float64) {
start := time.Now()
for i := 0; i < 500000; i++ {
io.Marshal(m)
}
stop := time.Now()
fmt.Println((stop.UnixNano() - start.UnixNano()) / 1000000)
}
func main() {
m := make(map[string]float64)
m["e"] = math.E
m["pi"] = math.Pi
m["ln2"] = math.Ln2
test(m)
io.RegisterMapEncoder((map[string]float64)(nil), stringFloat64MapEncoder)
test(m)
}
Go
1
https://gitee.com/andot/hprose-go.git
git@gitee.com:andot/hprose-go.git
andot
hprose-go
hprose-go
v2.0.4

搜索帮助

53164aa7 5694891 3bd8fe86 5694891