Skip to content

Commit f08595a

Browse files
author
Eero Norri
committed
Add benchmark tests for Len() in simple policy
1 parent 9c6b76a commit f08595a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

policy/simple/example_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package simple_test
22

33
import (
44
"fmt"
5+
"testing"
56

67
"github.com/Code-Hex/go-generics-cache/policy/simple"
78
)
@@ -47,3 +48,23 @@ func ExampleCache_Keys() {
4748
// bar
4849
// baz
4950
}
51+
52+
func BenchmarkLenWithKeys(b *testing.B) {
53+
c := simple.NewCache[string, int]()
54+
c.Set("foo", 1)
55+
c.Set("bar", 2)
56+
c.Set("baz", 3)
57+
for i := 0; i < b.N; i++ {
58+
var _ = len(c.Keys())
59+
}
60+
}
61+
62+
func BenchmarkJustLen(b *testing.B) {
63+
c := simple.NewCache[string, int]()
64+
c.Set("foo", 1)
65+
c.Set("bar", 2)
66+
c.Set("baz", 3)
67+
for i := 0; i < b.N; i++ {
68+
var _ = c.Len()
69+
}
70+
}

0 commit comments

Comments
 (0)