New upstream version 1.6.0+ds
Sascha Steinbiss
4 years ago
0 | package bench | |
1 | ||
2 | import ( | |
3 | "testing" | |
4 | "time" | |
5 | ||
6 | "github.com/ReneKroon/ttlcache" | |
7 | ) | |
8 | ||
9 | func BenchmarkCacheSetWithoutTTL(b *testing.B) { | |
10 | cache := ttlcache.NewCache() | |
11 | defer cache.Close() | |
12 | ||
13 | for n := 0; n < b.N; n++ { | |
14 | cache.Set(string(n%1000000), "value") | |
15 | } | |
16 | } | |
17 | ||
18 | func BenchmarkCacheSetWithGlobalTTL(b *testing.B) { | |
19 | cache := ttlcache.NewCache() | |
20 | defer cache.Close() | |
21 | ||
22 | cache.SetTTL(time.Duration(50 * time.Millisecond)) | |
23 | for n := 0; n < b.N; n++ { | |
24 | cache.Set(string(n%1000000), "value") | |
25 | } | |
26 | } | |
27 | ||
28 | func BenchmarkCacheSetWithTTL(b *testing.B) { | |
29 | cache := ttlcache.NewCache() | |
30 | defer cache.Close() | |
31 | ||
32 | for n := 0; n < b.N; n++ { | |
33 | cache.SetWithTTL(string(n%1000000), "value", time.Duration(50*time.Millisecond)) | |
34 | } | |
35 | } |