Skip to content

Commit

Permalink
add chi benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Oct 17, 2018
1 parent e68107d commit 444971b
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 11 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<a href="https://twitter.com/MakisMaropoulos">Gerasimos Maropoulos</a>
</div>

[![Benchmark chart between muxie, httprouter, gin, gorilla mux, echo and vestigo](_benchmarks/chart-16-oct-2018.png)](_benchmarks)
<!-- [![Benchmark chart between muxie, httprouter, gin, gorilla mux, echo, vestigo and chi](_benchmarks/chart-17-oct-2018.png)](_benchmarks)
_Last updated on October 16, 2018._ Click [here](_benchmarks/README.md) to read more details.
_Last updated on October 17, 2018._ Click [here](_benchmarks/README.md) to read more details. -->

## Features

- __trie based:__ performance and useness are first class citizens, Muxie is based on the prefix tree data structure, designed from scratch and built for HTTP, and it is among the fastest outhere, if not the fastest one
- __trie based:__ [performance](_benchmarks/README.md) and useness are first class citizens, Muxie is based on the prefix tree data structure, designed from scratch and built for HTTP, and it is among the fastest outhere, if not the fastest one
- __grouping:__ group common routes based on their path prefixes
- __no external dependencies:__ weighing `30kb`, Muxie is a tiny little library without external dependencies
- __closet wildcard resolution and custom 404:__ wildcards, named parameters and static paths can all live and play together nice and fast in the same path prefix(!)
Expand All @@ -75,13 +75,18 @@ import (
"fmt"
"net/http"

"github.com/rs/cors"

"github.com/kataras/muxie"
)

func main() {
mux := muxie.NewMux()
mux.PathCorrection = true

// _examples/6_middleware
mux.Use(cors.Default().Handler)

mux.HandleFunc("/", indexHandler)
// Root wildcards, can be used for site-level custom not founds(404).
mux.HandleFunc("/*path", notFoundHandler)
Expand Down
24 changes: 16 additions & 8 deletions _benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Benchmarks
![Benchmark chart between muxie, httprouter, gin, gorilla mux, echo, vestigo and chi](chart-17-oct-2018.png)

Last updated on October 16, 2018.
Higher is better.

> October 16: add echo and vestigo benchmarks against the same environments
Last updated on October 17, 2018.

> October 16 & 17: add echo, vestigo and chi benchmarks against the same environments
> October 15: benchmark between muxie, httprouter, gin and gorilla mux
Expand All @@ -28,13 +30,11 @@ Last updated on October 16, 2018.
* Bench code: [echo/main.go](echo/main.go)
* **vestigo**: https://github.com/husobee/vestigo, latest version **1.1.0**
* Bench code: [vestigo/main.go](vestigo/main.go)
* **chi**: https://github.com/go-chi/chi, latest version **3.3.3**
* Bench code: [chi/main.go](chi/main.go)

## Results

![Benchmark chart between muxie, httprouter, gin, gorilla mux, echo and vestigo](chart-16-oct-2018.png)

> Higher is better
### Static Path

```sh
Expand Down Expand Up @@ -65,6 +65,10 @@ bombardier -c 125 -n 1000000 http://localhost:3000

![](static_path_vestigo.png)

#### Chi

![](static_path_chi.png)

### Parameterized (dynamic) Path

```sh
Expand Down Expand Up @@ -93,4 +97,8 @@ bombardier -c 125 -n 1000000 http://localhost:3000/user/42

#### Vestigo

![](parameterized_path_vestigo.png)
![](parameterized_path_vestigo.png)

#### Chi

![](parameterized_path_chi.png)
Binary file removed _benchmarks/chart-16-oct-2018.png
Binary file not shown.
Binary file added _benchmarks/chart-17-oct-2018.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions _benchmarks/chi/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"net/http"

"github.com/go-chi/chi"
)

func main() {
r := chi.NewRouter()

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Welcome!\n"))
})

r.Get("/user/{id}", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(chi.URLParam(r, "id")))
})

fmt.Println("Server started at localhost:3000")
http.ListenAndServe(":3000", r)
}
Binary file added _benchmarks/parameterized_path_chi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _benchmarks/static_path_chi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _benchmarks/static_path_gorilla-mux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _benchmarks/static_path_muxie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _benchmarks/static_path_vestigo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 444971b

Please sign in to comment.