gf/os/grpool/grpool_z_bench_test.go
2021-11-17 23:20:58 +08:00

53 lines
909 B
Go

// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// 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.
// go test *.go -bench=".*"
package grpool_test
import (
"context"
"testing"
"github.com/gogf/gf/v2/os/grpool"
)
var (
ctx = context.TODO()
n = 500000
)
func increment(ctx context.Context) {
for i := 0; i < 1000000; i++ {
}
}
func BenchmarkGrpool_1(b *testing.B) {
for i := 0; i < b.N; i++ {
grpool.Add(ctx, increment)
}
}
func BenchmarkGoroutine_1(b *testing.B) {
for i := 0; i < b.N; i++ {
go increment(ctx)
}
}
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)
}
}