Browse Source

Benchmark goji/web in parallel

Test with `go test -cpu`.

In other news, Goji is really really fast. Who knew!
Carl Jackson 11 years ago
parent
commit
a452de8605
1 changed files with 15 additions and 6 deletions
  1. +15
    -6
      web/bench_test.go

+ 15
- 6
web/bench_test.go View File

@ -93,13 +93,18 @@ func benchN(b *testing.B, n int) {
for _, prefix := range prefixes { for _, prefix := range prefixes {
addRoutes(m, prefix) addRoutes(m, prefix)
} }
m.Compile()
reqs := permuteRequests(genRequests(prefixes)) reqs := permuteRequests(genRequests(prefixes))
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() 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) { func benchM(b *testing.B, n int) {
@ -109,18 +114,22 @@ func benchM(b *testing.B, n int) {
m.Use(trivialMiddleware) m.Use(trivialMiddleware)
} }
r, _ := http.NewRequest("GET", "/", nil) r, _ := http.NewRequest("GET", "/", nil)
m.Compile()
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() 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) { func BenchmarkStatic(b *testing.B) {
m := New() m := New()
m.Get("/", nilRouter{}) m.Get("/", nilRouter{})
r, _ := http.NewRequest("GET", "/", nil) r, _ := http.NewRequest("GET", "/", nil)
m.Compile()
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()


Loading…
Cancel
Save