可能是目前最快的struct複製庫

liguangsheng發表於2019-02-24

https://github.com/liguangsheng/go-copy

  • 基於快取避免重複分析struct
  • 基於reflect2避免了reflect.Value消耗
  • 自定義複製,支援time.Time複製到int64
  • 自定義tag

看的上的麻煩點個star,多謝各位了

目前還沒有經過特別嚴謹的測試,有問題歡迎提issue

λ go test -bench=. -benchmem
goos: windows
goarch: amd64
pkg: github.com/liguangsheng/go-copy/_benchmark
BenchmarkJinzhuCopyBig-8           10000            101620 ns/op           68848 B/op        487 allocs/op
BenchmarkDeepCopyBig-8              1000           1848412 ns/op         1907780 B/op      25759 allocs/op
BenchmarkJSONCopyBig-8             50000             27703 ns/op            4758 B/op        152 allocs/op
BenchmarkCopyBig-8                200000             11964 ns/op            2512 B/op        102 allocs/op (this repo)
BenchmarkJinzhuCopyMedium-8       200000              6971 ns/op            7320 B/op         58 allocs/op
BenchmarkDeepCopyMedium-8          50000             26620 ns/op           21672 B/op        331 allocs/op
BenchmarkJSONCopyMedium-8         500000              2817 ns/op             472 B/op         17 allocs/op
BenchmarkCopyMedium-8            1000000              1453 ns/op             272 B/op         12 allocs/op (this repo)
BenchmarkJinzhuCopySmall-8       1000000              2090 ns/op            1616 B/op         21 allocs/op
BenchmarkDeepCopySmall-8          300000              3816 ns/op            2520 B/op         49 allocs/op
BenchmarkJSONCopySmall-8         2000000               814 ns/op             104 B/op          5 allocs/op
BenchmarkCopySmall-8             3000000               586 ns/op              96 B/op          5 allocs/op (this repo)
PASS
ok      github.com/liguangsheng/go-copy/_benchmark      21.368s

相關文章