-
-
Save oranie/2cb7e822a7405ff0c416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To run this test. | |
// $ go get github.com/garyburd/redigo/redis | |
// $ go test -bench=. | |
package main | |
import ( | |
"fmt" | |
"log" | |
"math/rand" | |
"testing" | |
"github.com/garyburd/redigo/redis" | |
) | |
var client redis.Conn | |
func init() { | |
var err error | |
client, err = redis.Dial("tcp", ":6379") | |
if err != nil { | |
log.Panic(err) | |
} | |
} | |
func BenchmarkSet(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_, err := client.Do("SET", "foo", i) | |
if err != nil { | |
b.Fatal(err) | |
} | |
} | |
} | |
func BenchmarkSetRandom(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
key := fmt.Sprintf("bench-%d", rand.Int31()) | |
_, err := client.Do("SET", key, rand.Int31()) | |
if err != nil { | |
b.Fatal(err) | |
} | |
} | |
} | |
func BenchmarkHSet(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_, err := client.Do("HSET", "bench", i, i) | |
if err != nil { | |
b.Fatal(err) | |
} | |
} | |
} | |
func BenchmarkHSetRandom(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_, err := client.Do("HSET", "bench", rand.Int31(), rand.Int31()) | |
if err != nil { | |
b.Fatal(err) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BenchmarkSet 50000 54748 ns/op | |
BenchmarkSetRandom 50000 55701 ns/op | |
BenchmarkHSet 50000 52575 ns/op | |
BenchmarkHSetRandom 50000 58658 ns/op | |
ok _/Users/inada-n/work/redis-benchmark 13.466s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment