Skip to content

Commit e2a702d

Browse files
authored
Merge pull request #1 from bmf-san/feature/impl-repo-setup
Setup repository
2 parents 23e1e43 + a6c2450 commit e2a702d

15 files changed

+899
-1
lines changed

.circleci/config.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
version: 2.1
2+
3+
orbs:
4+
codecov: codecov/[email protected]
5+
6+
jobs:
7+
"test":
8+
parameters:
9+
version:
10+
type: string
11+
modules:
12+
type: boolean
13+
default: true
14+
docker:
15+
- image: "cimg/go:<< parameters.version >>"
16+
working_directory: ~/go/src/github.com/bmf-san/goblin
17+
environment:
18+
GO111MODULE: "on"
19+
steps:
20+
- checkout
21+
- run:
22+
name: "Go version"
23+
command: go version
24+
- run:
25+
name: "Fetch dependencies"
26+
command: go mod download
27+
- run:
28+
name: "Run gofmt"
29+
command: make gofmt
30+
- run:
31+
name: "Run vet"
32+
command: make vet
33+
- run:
34+
name: "Run go test-benchmark"
35+
command: make test-benchmark
36+
- when:
37+
condition:
38+
or:
39+
- equal: [ '1.19', << parameters.version >> ]
40+
- equal: [ '1.18', << parameters.version >> ]
41+
steps:
42+
- run:
43+
name: "Install tools"
44+
command: make install-tools
45+
- run:
46+
name: "Run go staticcheck"
47+
command: make staticcheck
48+
workflows:
49+
tests:
50+
jobs:
51+
- test:
52+
matrix:
53+
parameters:
54+
version: ["1.19", "1.18", "1.17"]

.github/CODE_OF_CONDUCT.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

.github/CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Contributing
2+
3+
1. Fork ([https://github.com/bmf-san/go-router-benchmark/fork](https://github.com/bmf-san/go-router-benchmark/fork))
4+
2. Create a feature branch
5+
3. Commit your changes
6+
4. Rebase your local changes against the master branch
7+
5. Fix your codes if CI failed.
8+
6. Create new Pull Request

.github/FUNDING.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [bmf-san]

.github/ISSUE_TEMPLATE/bug_report.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
5+
---
6+
7+
# Description
8+
9+
# Expected Behavior
10+
11+
# Current Behavior
12+
13+
# Steps to Reproduce
14+
1.
15+
2.
16+
3.
17+
4.
18+
19+
# Environment
20+
<!--- Tell us your go version. -->
21+
22+
# Possible Solution
23+
<!--- Not obligatory, but tell us if you have any ideas. -->
24+
25+
# Possible Implementation
26+
<!--- Not obligatory, but tell us if you have any ideas. -->
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
# Description
8+
9+
# Describe the feature you'd like to request
10+
11+
# Describe the solution you'd like
12+
<!--- Not obligatory -->

.github/ISSUE_TEMPLATE/question.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
name: Question
3+
about: Create a report to ask any quetions.
4+
5+
---
6+
7+
# Question

.github/PULL_REQUEST_TEMPLATE.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Description
2+
3+
# Changes
4+
5+
# Impact range
6+
7+
# Operational Requirements
8+
9+
# Related Issue
10+
<!--- Not obligatory, but write any issues if exists it -->
11+
12+
# Supplement
13+
<!--- Not obligatory -->

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
time: "10:00"
8+
timezone: "Asia/Tokyo"

Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: help
2+
3+
help:
4+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
5+
6+
.DEFAULT_GOAL := help
7+
8+
.PHONY: install-tools
9+
install-tools: ## Install staticcheck.
10+
ifeq ($(shell command -v staticcheck 2> /dev/null),)
11+
go install honnef.co/go/tools/cmd/staticcheck@latest
12+
endif
13+
ifeq ($(shell command -v goimports 2> /dev/null),)
14+
go install golang.org/x/tools/cmd/goimports@latest
15+
endif
16+
17+
.PHONY: gofmt
18+
gofmt: ## Run gofmt.
19+
test -z "$(gofmt -s -l . | tee /dev/stderr)"
20+
21+
.PHONY: goimports
22+
goimports: ## Run goimports.
23+
goimports -d $(find . -type f -name '*.go' -not -path "./vendor/*")
24+
25+
.PHONY: vet
26+
vet: ## Run vet.
27+
go vet -v ./...
28+
29+
.PHONY: staticcheck
30+
staticcheck: ## Run staticcheck.
31+
staticcheck ./...
32+
33+
.PHONY: test-benchmark
34+
test-benchmark: ## Run benchmark tests.
35+
go test -bench=. -benchmem

README.md

+110-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,111 @@
11
# go-router-benchmark
2-
Benchmark test for http router implemented in golang.
2+
Compare the performance of routers built with golang.
3+
4+
# Motivation
5+
I have implemented a router called [bmf-san/goblin](https://github.com/bmf-san/goblin), and I created this repository to compare it with other routers and get hints on how to improve [bmf-san/goblin](https://github.com/bmf-san/goblin).
6+
7+
Another reason is that [this nice repository](https://github.com/julienschmidt/go-http-routing-benchmark) seems to have stopped being maintained, so I wanted to have a benchmark test for the router that I could manage myself.
8+
9+
# Benchmark test
10+
This benchmark test is not a complete representation of router performance differences.
11+
12+
This is because it is difficult to prepare a perfect test case due to differences in router specifications and different data structures.
13+
14+
Benchmarks are obtained by narrowing down to specific functions.
15+
16+
# Listed routers
17+
- [bmf-san/goblin](https://github.com/bmf-san/goblin)
18+
- [julienschmidt/httprouter](https://github.com/julienschmidt/httprouter)
19+
- [go-chi/chi](https://github.com/go-chi/chi)
20+
- [gin-gonic/gin](https://github.com/gin-gonic/gin)
21+
- [uptrace/bunrouter](https://github.com/uptrace/bunrouter)
22+
- [dimfeld/httptreemux](https://github.com/dimfeld/httptreemux)
23+
- [beego/mux](https://github.com/beego/mux)
24+
- [gorilla/mux](https://github.com/gorilla/mux)
25+
26+
# How to run benchmark test
27+
`make test-benchmark`
28+
29+
## Commands for running benchmark test
30+
`make test-benchmark`
31+
32+
## Results
33+
```
34+
go test -bench=. -benchmem
35+
goos: linux
36+
goarch: amd64
37+
pkg: github.com/go-router-benchmark
38+
cpu: Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz
39+
BenchmarkStaticRoutesRootGoblin-36 27648112 43.35 ns/op 0 B/op 0 allocs/op
40+
BenchmarkStaticRoutes1Goblin-36 9083848 128.1 ns/op 16 B/op 1 allocs/op
41+
BenchmarkStaticRoutes5Goblin-36 3331718 353.7 ns/op 80 B/op 1 allocs/op
42+
BenchmarkStaticRoutes10Goblin-36 1874312 577.7 ns/op 160 B/op 1 allocs/op
43+
BenchmarkPathParamColonRoutes1Goblin-36 1241379 991.9 ns/op 409 B/op 6 allocs/op
44+
BenchmarkPathParamColonRoutes5Goblin-36 388048 3391 ns/op 966 B/op 13 allocs/op
45+
BenchmarkPathParamColonRoutes10Goblin-36 187884 5993 ns/op 1613 B/op 19 allocs/op
46+
BenchmarkStaticRoutesRootHTTPRouter-36 90323350 13.58 ns/op 0 B/op 0 allocs/op
47+
BenchmarkStaticRoutes1HTTPRouter-36 89596381 13.24 ns/op 0 B/op 0 allocs/op
48+
BenchmarkStaticRoutes5HTTPRouter-36 86710161 13.22 ns/op 0 B/op 0 allocs/op
49+
BenchmarkStaticRoutes10HTTPRouter-36 87476588 13.23 ns/op 0 B/op 0 allocs/op
50+
BenchmarkPathParamColonRoutes1HTTPRouter-36 15888105 72.22 ns/op 32 B/op 1 allocs/op
51+
BenchmarkPathParamColonRoutes5HTTPRouter-36 6374383 203.8 ns/op 160 B/op 1 allocs/op
52+
BenchmarkPathParamColonRoutes10HTTPRouter-36 3814080 330.8 ns/op 320 B/op 1 allocs/op
53+
BenchmarkStaticRoutesRootChi-36 3499848 332.7 ns/op 304 B/op 2 allocs/op
54+
BenchmarkStaticRoutes1Chi-36 3483327 349.8 ns/op 304 B/op 2 allocs/op
55+
BenchmarkStaticRoutes5Chi-36 3650314 329.0 ns/op 304 B/op 2 allocs/op
56+
BenchmarkStaticRoutes10Chi-36 3711537 327.3 ns/op 304 B/op 2 allocs/op
57+
BenchmarkPathParamBracketRoutes1Chi-36 3403273 377.5 ns/op 304 B/op 2 allocs/op
58+
BenchmarkPathParamBracketRoutes5Chi-36 1919821 618.9 ns/op 304 B/op 2 allocs/op
59+
BenchmarkPathParamBracketRoutes10Chi-36 1407243 810.2 ns/op 304 B/op 2 allocs/op
60+
BenchmarkStaticRoutesRootGin-36 24909394 47.58 ns/op 0 B/op 0 allocs/op
61+
BenchmarkStaticRoutes1Gin-36 25048821 48.07 ns/op 0 B/op 0 allocs/op
62+
BenchmarkStaticRoutes5Gin-36 24995527 49.40 ns/op 0 B/op 0 allocs/op
63+
BenchmarkStaticRoutes10Gin-36 21957733 52.95 ns/op 0 B/op 0 allocs/op
64+
BenchmarkPathParamColonRoutes1Gin-36 18214605 58.94 ns/op 0 B/op 0 allocs/op
65+
BenchmarkPathParamColonRoutes5Gin-36 10900795 118.0 ns/op 0 B/op 0 allocs/op
66+
BenchmarkPathParamColonRoutes10Gin-36 6629413 190.5 ns/op 0 B/op 0 allocs/op
67+
BenchmarkStaticRoutesRootBunRouter-36 54979360 22.09 ns/op 0 B/op 0 allocs/op
68+
BenchmarkStaticRoutes1BunRouter-36 41570702 27.26 ns/op 0 B/op 0 allocs/op
69+
BenchmarkStaticRoutes5BunRouter-36 41219000 28.62 ns/op 0 B/op 0 allocs/op
70+
BenchmarkStaticRoutes10BunRouter-36 40128004 31.01 ns/op 0 B/op 0 allocs/op
71+
BenchmarkPathParamColonRoutes1BunRouter-36 35211588 33.75 ns/op 0 B/op 0 allocs/op
72+
BenchmarkPathParamColonRoutes5BunRouter-36 10227812 117.4 ns/op 0 B/op 0 allocs/op
73+
BenchmarkPathParamColonRoutes10BunRouter-36 5063023 248.2 ns/op 0 B/op 0 allocs/op
74+
BenchmarkStaticRoutesRootHTTPTreeMux-36 4521781 286.4 ns/op 328 B/op 3 allocs/op
75+
BenchmarkStaticRoutes1HTTPTreeMux-36 4056072 293.4 ns/op 328 B/op 3 allocs/op
76+
BenchmarkStaticRoutes5HTTPTreeMux-36 3465921 367.0 ns/op 328 B/op 3 allocs/op
77+
BenchmarkStaticRoutes10HTTPTreeMux-36 2574319 450.1 ns/op 328 B/op 3 allocs/op
78+
BenchmarkPathParamColonRoutes1HTTPTreeMux-36 2202633 540.6 ns/op 680 B/op 6 allocs/op
79+
BenchmarkPathParamColonRoutes5HTTPTreeMux-36 1000000 1106 ns/op 904 B/op 9 allocs/op
80+
BenchmarkPathParamColonRoutes10HTTPTreeMux-36 572616 2174 ns/op 1742 B/op 11 allocs/op
81+
BenchmarkStaticRoutesRootBeegoMux-36 13203564 81.36 ns/op 32 B/op 1 allocs/op
82+
BenchmarkStaticRoutes1BeegoMux-36 14425970 96.34 ns/op 32 B/op 1 allocs/op
83+
BenchmarkStaticRoutes5BeegoMux-36 6515413 172.7 ns/op 32 B/op 1 allocs/op
84+
BenchmarkStaticRoutes10BeegoMux-36 4286169 282.6 ns/op 32 B/op 1 allocs/op
85+
BenchmarkPathParamColonRoutes1BeegoMux-36 2392867 499.6 ns/op 672 B/op 5 allocs/op
86+
BenchmarkPathParamColonRoutes5BeegoMux-36 1725937 697.6 ns/op 672 B/op 5 allocs/op
87+
BenchmarkPathParamColonRoutes10BeegoMux-36 710916 1486 ns/op 1254 B/op 6 allocs/op
88+
BenchmarkStaticRoutesRootGorillaMux-36 1636922 729.3 ns/op 721 B/op 7 allocs/op
89+
BenchmarkStaticRoutes1GorillaMux-36 1612135 779.3 ns/op 721 B/op 7 allocs/op
90+
BenchmarkStaticRoutes5GorillaMux-36 1408734 881.1 ns/op 721 B/op 7 allocs/op
91+
BenchmarkStaticRoutes10GorillaMux-36 1243224 956.0 ns/op 721 B/op 7 allocs/op
92+
BenchmarkPathParamBracketRoutes1GorillaMux-36 1000000 1165 ns/op 1026 B/op 8 allocs/op
93+
BenchmarkPathParamBracketRoutes5GorillaMux-36 477472 2191 ns/op 1090 B/op 8 allocs/op
94+
BenchmarkPathParamBracketRoutes10GorillaMux-36 287336 4409 ns/op 1754 B/op 9 allocs/op
95+
PASS
96+
ok github.com/go-router-benchmark 82.889s
97+
```
98+
99+
# Contribution
100+
We are always accepting issues, pull requests, and other requests and questions.
101+
102+
We look forward to your contribution!
103+
104+
# License
105+
This project is licensed under the terms of the MIT license.
106+
107+
## Author
108+
bmf - A Web Developer in Japan.
109+
110+
- [@bmf-san](https://twitter.com/bmf_san)
111+
- [bmf-tech](http://bmf-tech.com/)

0 commit comments

Comments
 (0)