mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
groutine性能测试用例
This commit is contained in:
@ -13,21 +13,18 @@ import (
|
||||
"gitee.com/johng/gf/g/os/groutine"
|
||||
)
|
||||
|
||||
func test() {
|
||||
num := 0
|
||||
for i := 0; i < 1000000; i++ {
|
||||
num += i
|
||||
}
|
||||
func increment() {
|
||||
for i := 0; i < 1000000; i++ {}
|
||||
}
|
||||
|
||||
func BenchmarkGroutine(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
groutine.Add(test)
|
||||
groutine.Add(increment)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGoRoutine(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
go test()
|
||||
go increment()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user