github.com/gogf/gf@v1.16.9/os/gcache/gcache_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 // go test *.go -bench=".*" -benchmem 8 9 package gcache_test 10 11 import ( 12 "testing" 13 14 "github.com/gogf/gf/os/gcache" 15 ) 16 17 var ( 18 localCache = gcache.New() 19 localCacheLru = gcache.New(10000) 20 ) 21 22 func Benchmark_CacheSet(b *testing.B) { 23 b.RunParallel(func(pb *testing.PB) { 24 i := 0 25 for pb.Next() { 26 localCache.Set(i, i, 0) 27 i++ 28 } 29 }) 30 } 31 32 func Benchmark_CacheGet(b *testing.B) { 33 b.RunParallel(func(pb *testing.PB) { 34 i := 0 35 for pb.Next() { 36 localCache.Get(i) 37 i++ 38 } 39 }) 40 } 41 42 func Benchmark_CacheRemove(b *testing.B) { 43 b.RunParallel(func(pb *testing.PB) { 44 i := 0 45 for pb.Next() { 46 localCache.Remove(i) 47 i++ 48 } 49 }) 50 } 51 52 func Benchmark_CacheLruSet(b *testing.B) { 53 b.RunParallel(func(pb *testing.PB) { 54 i := 0 55 for pb.Next() { 56 localCacheLru.Set(i, i, 0) 57 i++ 58 } 59 }) 60 } 61 62 func Benchmark_CacheLruGet(b *testing.B) { 63 b.RunParallel(func(pb *testing.PB) { 64 i := 0 65 for pb.Next() { 66 localCacheLru.Get(i) 67 i++ 68 } 69 }) 70 } 71 72 func Benchmark_CacheLruRemove(b *testing.B) { 73 b.RunParallel(func(pb *testing.PB) { 74 i := 0 75 for pb.Next() { 76 localCacheLru.Remove(i) 77 i++ 78 } 79 }) 80 }