sm
/
cache
1
0
Fork 0

A few benchmarks vs. normal maps

This commit is contained in:
Patrick Mylund Nielsen 2012-01-04 09:55:32 +01:00
parent 9e6775b151
commit e46251e025
1 changed files with 47 additions and 0 deletions

View File

@ -408,3 +408,50 @@ func TestFlush(t *testing.T) {
t.Error("x is not nil:", x)
}
}
func BenchmarkCache(b *testing.B) {
tc := New(0, 0)
tc.Set("foo", "bar", 0)
for i := 0; i < b.N; i++ {
tc.Get("foo")
}
}
func BenchmarkMap(b *testing.B) {
m := map[string]string{
"foo": "bar",
}
for i := 0; i < b.N; i++ {
_, _ = m["foo"]
}
}
func BenchmarkCacheSet(b *testing.B) {
tc := New(0, 0)
for i := 0; i < b.N; i++ {
tc.Set("foo", "bar", 0)
}
}
func BenchmarkMapSet(b *testing.B) {
m := map[string]string{}
for i := 0; i < b.N; i++ {
m["foo"] = "bar"
}
}
func BenchmarkCacheSetDelete(b *testing.B) {
tc := New(0, 0)
for i := 0; i < b.N; i++ {
tc.Set("foo", "bar", 0)
tc.Delete("foo")
}
}
func BenchmarkMapSetDelete(b *testing.B) {
m := map[string]string{}
for i := 0; i < b.N; i++ {
m["foo"] = "bar"
delete(m, "foo")
}
}