浏览代码

Add more benchmarks

Ask Bjørn Hansen 9 年之前
父节点
当前提交
67bc94d4ac
共有 2 个文件被更改,包括 21 次插入1 次删除
  1. 3 0
      Makefile
  2. 18 1
      serve_test.go

+ 3 - 0
Makefile

@@ -6,3 +6,6 @@ templates.go: templates/*.html monitor.go
 
 devel:
 	go build -tags devel
+
+bench:
+	go test -check.b -check.bmem

+ 18 - 1
serve_test.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"math/rand"
 	"net"
 	"strings"
 	"sync"
@@ -222,12 +223,28 @@ func (s *ServeSuite) TestServeRace(c *C) {
 	wg.Wait()
 }
 
-func (s *ServeSuite) BenchmarkServing(c *C) {
+func (s *ServeSuite) BenchmarkServingCountryDebug(c *C) {
 	for i := 0; i < c.N; i++ {
 		exchange(c, "_country.foo.pgeodns.", dns.TypeTXT)
 	}
 }
 
+func (s *ServeSuite) BenchmarkServing(c *C) {
+
+	// a deterministic seed is the default anyway, but let's be explicit we want it here.
+	rnd := rand.NewSource(1)
+
+	testNames := []string{"foo.test.example.com.", "one.test.example.com.",
+		"weight.test.example.com.", "three.two.one.test.example.com.",
+		"bar.test.example.com.", "0-alias.test.example.com.",
+	}
+
+	for i := 0; i < c.N; i++ {
+		name := testNames[rnd.Int63()%int64(len(testNames))]
+		exchange(c, name, dns.TypeA)
+	}
+}
+
 func exchangeSubnet(c *C, name string, dnstype uint16, ip string) *dns.Msg {
 	msg := new(dns.Msg)