read file size and number of samples for benchmark test from flags

The values default to what we used previously.
This commit is contained in:
Marten Seemann
2017-07-25 11:16:58 +07:00
parent d108e10420
commit 30bcc48e52
2 changed files with 68 additions and 53 deletions

View File

@@ -1,6 +1,8 @@
package benchmark
import (
"flag"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -11,3 +13,14 @@ func TestBenchmark(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Benchmark Suite")
}
var (
size int // file size in MB, will be read from flags
samples int // number of samples for Measure, will be read from flags
)
func init() {
flag.IntVar(&size, "size", 50, "data length (in MB)")
flag.IntVar(&samples, "samples", 6, "number of samples")
flag.Parse()
}

View File

@@ -15,8 +15,9 @@ import (
. "github.com/onsi/gomega"
)
func init() {
var _ = Describe("Benchmarks", func() {
dataLen := 50 /* MB */ * (1 << 20)
dataLen := size * /* MB */ (1 << 20)
data := make([]byte, dataLen)
rand.Seed(GinkgoRandomSeed())
rand.Read(data) // no need to check for an error. math.Rand.Read never errors
@@ -25,7 +26,7 @@ var _ = Describe("Benchmarks", func() {
version := protocol.SupportedVersions[i]
Context(fmt.Sprintf("with version %d", version), func() {
Measure("transferring a file", func(b Benchmarker) {
Measure(fmt.Sprintf("transferring a %d MB file", size), func(b Benchmarker) {
var ln quic.Listener
serverAddr := make(chan net.Addr)
handshakeChan := make(chan struct{})
@@ -71,7 +72,8 @@ var _ = Describe("Benchmarks", func() {
ln.Close()
sess.Close(nil)
}, 6)
}, samples)
})
}
})
}