Skip to content

Commit

Permalink
Add a couple of simple benchmarks for set/get
Browse files Browse the repository at this point in the history
  • Loading branch information
fiam committed Oct 28, 2013
1 parent eafcd9e commit 190047c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions memcache/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package memcache

import (
"strings"
"testing"
)

func benchmarkSetGet(b *testing.B, item *Item) {
cmd, c := newUnixServer(b)
key := item.Key
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := c.Set(item); err != nil {
b.Error(err)
}
if _, err := c.Get(key); err != nil {
b.Error(err)
}
}
b.StopTimer()
cmd.Process.Kill()
cmd.Wait()
}

func BenchmarkSetGet(b *testing.B) {
benchmarkSetGet(b, &Item{Key: "foo", Value: []byte("bar")})
}

func BenchmarkSetGetLarge(b *testing.B) {
key := strings.Repeat("f", 240)
value := make([]byte, 1024)
benchmarkSetGet(b, &Item{Key: key, Value: value})
}

0 comments on commit 190047c

Please sign in to comment.