Browse Source

Add benchmarks.

Gary Burd 11 years ago
parent
commit
e30d52b4c9
2 changed files with 93 additions and 0 deletions
  1. 30 0
      redis/conn_test.go
  2. 63 0
      redis/pool_test.go

+ 30 - 0
redis/conn_test.go

@@ -373,3 +373,33 @@ func ExampleDial(x int) {
 	}
 	}
 	defer c.Close()
 	defer c.Close()
 }
 }
+
+func BenchmarkDoEmpty(b *testing.B) {
+	b.StopTimer()
+	c, err := redis.DialTestDB()
+	if err != nil {
+		b.Fatal(err)
+	}
+	defer c.Close()
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		if _, err := c.Do(""); err != nil {
+			b.Fatal(err)
+		}
+	}
+}
+
+func BenchmarkDoPing(b *testing.B) {
+	b.StopTimer()
+	c, err := redis.DialTestDB()
+	if err != nil {
+		b.Fatal(err)
+	}
+	defer c.Close()
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		if _, err := c.Do("PING"); err != nil {
+			b.Fatal(err)
+		}
+	}
+}

+ 63 - 0
redis/pool_test.go

@@ -201,6 +201,8 @@ func TestPoolTimeout(t *testing.T) {
 	c.Close()
 	c.Close()
 
 
 	d.check("2", p, 2, 1)
 	d.check("2", p, 2, 1)
+
+	p.Close()
 }
 }
 
 
 func TestBorrowCheck(t *testing.T) {
 func TestBorrowCheck(t *testing.T) {
@@ -217,6 +219,7 @@ func TestBorrowCheck(t *testing.T) {
 		c.Close()
 		c.Close()
 	}
 	}
 	d.check("1", p, 10, 1)
 	d.check("1", p, 10, 1)
+	p.Close()
 }
 }
 
 
 func TestMaxActive(t *testing.T) {
 func TestMaxActive(t *testing.T) {
@@ -250,6 +253,7 @@ func TestMaxActive(t *testing.T) {
 	c3.Close()
 	c3.Close()
 
 
 	d.check("4", p, 2, 2)
 	d.check("4", p, 2, 2)
+	p.Close()
 }
 }
 
 
 func TestMonitorCleanup(t *testing.T) {
 func TestMonitorCleanup(t *testing.T) {
@@ -264,6 +268,7 @@ func TestMonitorCleanup(t *testing.T) {
 	c.Close()
 	c.Close()
 
 
 	d.check("", p, 1, 0)
 	d.check("", p, 1, 0)
+	p.Close()
 }
 }
 
 
 func TestPubSubCleanup(t *testing.T) {
 func TestPubSubCleanup(t *testing.T) {
@@ -293,6 +298,8 @@ func TestPubSubCleanup(t *testing.T) {
 		t.Errorf("got commands %v, want %v", d.commands, want)
 		t.Errorf("got commands %v, want %v", d.commands, want)
 	}
 	}
 	d.commands = nil
 	d.commands = nil
+
+	p.Close()
 }
 }
 
 
 func TestTransactionCleanup(t *testing.T) {
 func TestTransactionCleanup(t *testing.T) {
@@ -363,4 +370,60 @@ func TestTransactionCleanup(t *testing.T) {
 		t.Errorf("got commands %v, want %v", d.commands, want)
 		t.Errorf("got commands %v, want %v", d.commands, want)
 	}
 	}
 	d.commands = nil
 	d.commands = nil
+
+	p.Close()
+}
+
+func BenchmarkPoolGet(b *testing.B) {
+	b.StopTimer()
+	p := Pool{Dial: DialTestDB, MaxIdle: 2}
+	c := p.Get()
+	if err := c.Err(); err != nil {
+		b.Fatal(err)
+	}
+	c.Close()
+	defer p.Close()
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		c = p.Get()
+		c.Close()
+	}
+}
+
+func BenchmarkPoolGetErr(b *testing.B) {
+	b.StopTimer()
+	p := Pool{Dial: DialTestDB, MaxIdle: 2}
+	c := p.Get()
+	if err := c.Err(); err != nil {
+		b.Fatal(err)
+	}
+	c.Close()
+	defer p.Close()
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		c = p.Get()
+		if err := c.Err(); err != nil {
+			b.Fatal(err)
+		}
+		c.Close()
+	}
+}
+
+func BenchmarkPoolGetPing(b *testing.B) {
+	b.StopTimer()
+	p := Pool{Dial: DialTestDB, MaxIdle: 2}
+	c := p.Get()
+	if err := c.Err(); err != nil {
+		b.Fatal(err)
+	}
+	c.Close()
+	defer p.Close()
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		c = p.Get()
+		if _, err := c.Do("PING"); err != nil {
+			b.Fatal(err)
+		}
+		c.Close()
+	}
 }
 }