Files
gf/os/grpool/grpool_z_bench_test.go

53 lines
909 B
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2018-01-17 10:28:42 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2018-01-17 10:28:42 +08:00
// go test *.go -bench=".*"
package grpool_test
import (
"context"
2019-06-19 09:06:52 +08:00
"testing"
2019-07-29 21:01:19 +08:00
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/os/grpool"
2018-01-17 10:28:42 +08:00
)
var (
ctx = context.TODO()
2021-11-17 23:20:58 +08:00
n = 500000
)
func increment(ctx context.Context) {
2019-06-19 09:06:52 +08:00
for i := 0; i < 1000000; i++ {
}
2018-01-17 10:28:42 +08:00
}
func BenchmarkGrpool_1(b *testing.B) {
2019-06-19 09:06:52 +08:00
for i := 0; i < b.N; i++ {
grpool.Add(ctx, increment)
2019-06-19 09:06:52 +08:00
}
2018-01-17 10:28:42 +08:00
}
func BenchmarkGoroutine_1(b *testing.B) {
2019-06-19 09:06:52 +08:00
for i := 0; i < b.N; i++ {
go increment(ctx)
2019-06-19 09:06:52 +08:00
}
}
2021-11-17 23:20:58 +08:00
func BenchmarkGrpool2(b *testing.B) {
b.N = n
for i := 0; i < b.N; i++ {
grpool.Add(ctx, increment)
}
}
func BenchmarkGoroutine2(b *testing.B) {
b.N = n
for i := 0; i < b.N; i++ {
go increment(ctx)
}
}