gf/os/gcache/gcache_z_bench_test.go

82 lines
1.4 KiB
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2018-02-12 15:33:19 +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-02-12 15:33:19 +08:00
2018-09-17 09:52:24 +08:00
// go test *.go -bench=".*" -benchmem
2018-02-12 15:33:19 +08:00
2018-12-30 14:53:16 +08:00
package gcache_test
2018-02-12 15:33:19 +08:00
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/gcache"
2018-02-12 15:33:19 +08:00
)
var (
localCache = gcache.New()
localCacheLru = gcache.New(10000)
)
func Benchmark_CacheSet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
localCache.Set(ctx, i, i, 0)
i++
}
})
2018-02-12 15:33:19 +08:00
}
func Benchmark_CacheGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
localCache.Get(ctx, i)
i++
}
})
2018-02-12 15:33:19 +08:00
}
func Benchmark_CacheRemove(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
localCache.Remove(ctx, i)
i++
}
})
2018-09-18 00:01:10 +08:00
}
func Benchmark_CacheLruSet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
localCacheLru.Set(ctx, i, i, 0)
i++
}
})
2018-09-18 00:01:10 +08:00
}
func Benchmark_CacheLruGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
localCacheLru.Get(ctx, i)
i++
2019-06-19 09:06:52 +08:00
}
})
}
func Benchmark_CacheLruRemove(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
localCacheLru.Remove(context.TODO(), i)
i++
2019-06-19 09:06:52 +08:00
}
})
2018-09-18 00:01:10 +08:00
}