This repository has been archived by the owner on Apr 24, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added filters / middleware to routes
added experimental package added benchmarks
- Loading branch information
1 parent
2796b1e
commit 5498e2e
Showing
7 changed files
with
238 additions
and
225 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package bench | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/drone/routes" | ||
gorilla "code.google.com/p/gorilla/mux" | ||
"github.com/bmizerany/pat" | ||
) | ||
|
||
func HandlerOk(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "hello world") | ||
w.WriteHeader(http.StatusOK) | ||
} | ||
|
||
// Benchmark_Routes runs a benchmark against our custom Mux using the | ||
// default settings. | ||
func Benchmark_Routes(b *testing.B) { | ||
|
||
handler := routes.New() | ||
handler.Get("/person/:last/:first", HandlerOk) | ||
|
||
for i := 0; i < b.N; i++ { | ||
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil) | ||
w := httptest.NewRecorder() | ||
handler.ServeHTTP(w, r) | ||
} | ||
|
||
} | ||
|
||
// Benchmark_Web runs a benchmark against the pat.go Mux using the | ||
// default settings. | ||
func Benchmark_Pat(b *testing.B) { | ||
|
||
|
||
|
||
m := pat.New() | ||
m.Get("/person/:last/:first", http.HandlerFunc(HandlerOk)) | ||
|
||
for i := 0; i < b.N; i++ { | ||
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil) | ||
w := httptest.NewRecorder() | ||
m.ServeHTTP(w, r) | ||
} | ||
} | ||
|
||
// Benchmark_Gorilla runs a benchmark against the Gorilla Mux using | ||
// the default settings. | ||
func Benchmark_GorillaHandler(b *testing.B) { | ||
|
||
|
||
handler := gorilla.NewRouter() | ||
handler.HandleFunc("/person/{last}/{first}", HandlerOk) | ||
|
||
for i := 0; i < b.N; i++ { | ||
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil) | ||
w := httptest.NewRecorder() | ||
handler.ServeHTTP(w, r) | ||
} | ||
} | ||
|
||
// Benchmark_ServeMux runs a benchmark against the ServeMux Go function. | ||
// We use this to determine performance impact of our library, when compared | ||
// to the out-of-the-box Mux provided by Go. | ||
func Benchmark_ServeMux(b *testing.B) { | ||
|
||
mux := http.NewServeMux() | ||
mux.HandleFunc("/", HandlerOk) | ||
|
||
for i := 0; i < b.N; i++ { | ||
r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil) | ||
w := httptest.NewRecorder() | ||
mux.ServeHTTP(w, r) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Submodule routes
added at
2796b1
Oops, something went wrong.