4 Star 10 Fork 2

Gitee 极速下载/go-ioc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/mylxsw/go-ioc
克隆/下载
container_benchmark_test.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
package ioc_test
import (
"github.com/mylxsw/go-ioc"
"strconv"
"testing"
)
func buildContainer() ioc.Container {
cc := ioc.New()
cc.MS(func() *RoleService { return &RoleService{} })
cc.MS(func(userRepo *UserRepo) *UserService { return &UserService{repo: userRepo} })
cc.MS(func() *UserRepo { return &UserRepo{connStr: "oops, no connection"} })
cc.MS(func() InterfaceDemo { return demo1{} })
cc.MV("version", "1.0.0")
for i := 0; i < 100; i++ {
cc.MV("version-"+strconv.Itoa(i), "1.0.0")
}
cc.MS(func(userRepo *UserRepo, cc ioc.Container) *UserManager {
m := &UserManager{UserRepo: userRepo}
cc.MustAutoWire(m)
m.Field2 = "Hello, world"
return m
})
return cc
}
// 3161624 366.9 ns/op
// 3309002 356.6 ns/op
// 985084 1213 ns/op
// 646950 2054 ns/op
// 5368746 219.3 ns/op
func BenchmarkContainerImpl_Resolve(b *testing.B) {
cc := buildContainer()
for i := 0; i < b.N; i++ {
cc.MustResolve(func(userManager *UserManager) {
// DO NOTHING
})
}
}
// 3883568 281.9 ns/op
// 5913072 190.9 ns/op
// 1651430 687.5 ns/op
// 413727 2599 ns/op
func BenchmarkContainerImpl_Keys(b *testing.B) {
cc := buildContainer()
for i := 0; i < b.N; i++ {
cc.Keys()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/go-ioc.git
git@gitee.com:mirrors/go-ioc.git
mirrors
go-ioc
go-ioc
master

搜索帮助