From a452de8605db976edad45da8ac80985c1fd6fdf5 Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Sun, 15 Feb 2015 17:51:12 -0800 Subject: [PATCH] Benchmark goji/web in parallel Test with `go test -cpu`. In other news, Goji is really really fast. Who knew! --- web/bench_test.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/web/bench_test.go b/web/bench_test.go index 57ecf41..4cc7826 100644 --- a/web/bench_test.go +++ b/web/bench_test.go @@ -93,13 +93,18 @@ func benchN(b *testing.B, n int) { for _, prefix := range prefixes { addRoutes(m, prefix) } + m.Compile() reqs := permuteRequests(genRequests(prefixes)) b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { - m.ServeHTTP(w, reqs[i%len(reqs)]) - } + b.RunParallel(func(pb *testing.PB) { + i := 0 + for pb.Next() { + i++ + m.ServeHTTP(w, reqs[i%len(reqs)]) + } + }) } func benchM(b *testing.B, n int) { @@ -109,18 +114,22 @@ func benchM(b *testing.B, n int) { m.Use(trivialMiddleware) } r, _ := http.NewRequest("GET", "/", nil) + m.Compile() b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { - m.ServeHTTP(w, r) - } + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + m.ServeHTTP(w, r) + } + }) } func BenchmarkStatic(b *testing.B) { m := New() m.Get("/", nilRouter{}) r, _ := http.NewRequest("GET", "/", nil) + m.Compile() b.ResetTimer() b.ReportAllocs()