Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: sync part httprouter codes and reduce if/else #2163

Merged
merged 1 commit into from Dec 1, 2019
Merged

tree: sync part httprouter codes and reduce if/else #2163

merged 1 commit into from Dec 1, 2019

Conversation

thinkerou
Copy link
Member

@thinkerou thinkerou commented Dec 1, 2019

the pr includes three parts:

  1. use longestCommonPrefix from https://github.com/julienschmidt/httprouter/blob/master/tree.go#L20
  2. remove else statement to reduce indent
  3. sync the issue fixed wildcard conflict should panic but doesn't julienschmidt/httprouter#172

after:

➜  go-http-routing-benchmark git:(master) go test -bench=Gin
#GithubAPI Routes: 203
   Gin: 58512 Bytes

#GPlusAPI Routes: 13
   Gin: 4384 Bytes

#ParseAPI Routes: 26
   Gin: 7776 Bytes

#Static Routes: 157
   Gin: 34936 Bytes

goos: darwin
goarch: amd64
pkg: github.com/julienschmidt/go-http-routing-benchmark
BenchmarkGin_Param        	12134269	       100 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param5       	 6822183	       173 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param20      	 2442889	       479 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParamWrite   	 6708414	       168 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubStatic 	 9077402	       118 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubParam  	 5660514	       203 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubAll    	   26366	     43260 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusStatic  	13235361	        83.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusParam   	 9402622	       127 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlus2Params 	 6166275	       183 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusAll     	  577646	      1866 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseStatic  	12644926	        86.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseParam   	11198742	        99.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Parse2Params 	 9181192	       127 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseAll     	  319550	      3366 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_StaticAll    	   40864	     26833 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/julienschmidt/go-http-routing-benchmark	22.169s

before:

➜  go-http-routing-benchmark git:(master) go test -bench=Gin
#GithubAPI Routes: 203
   Gin: 58512 Bytes

#GPlusAPI Routes: 13
   Gin: 4384 Bytes

#ParseAPI Routes: 26
   Gin: 7776 Bytes

#Static Routes: 157
   Gin: 34936 Bytes

goos: darwin
goarch: amd64
pkg: github.com/julienschmidt/go-http-routing-benchmark
BenchmarkGin_Param        	10962327	       104 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param5       	 6442416	       179 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param20      	 2381566	       523 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParamWrite   	 6295077	       173 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubStatic 	 9231175	       130 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubParam  	 4975027	       219 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubAll    	   24982	     47799 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusStatic  	12289202	        96.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusParam   	 9156241	       138 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlus2Params 	 5860107	       210 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusAll     	  552486	      2111 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseStatic  	11597578	       105 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseParam   	 9847570	       113 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Parse2Params 	 7823059	       142 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseAll     	  290121	      3575 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_StaticAll    	   41952	     28302 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/julienschmidt/go-http-routing-benchmark	22.864s

@codecov
Copy link

codecov bot commented Dec 1, 2019

Codecov Report

Merging #2163 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2163      +/-   ##
==========================================
+ Coverage   98.61%   98.61%   +<.01%     
==========================================
  Files          40       40              
  Lines        2240     2242       +2     
==========================================
+ Hits         2209     2211       +2     
  Misses         16       16              
  Partials       15       15
Impacted Files Coverage Δ
tree.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3957f6b...3a579e4. Read the comment docs.

@thinkerou thinkerou added this to the 1.6 milestone Dec 1, 2019
@thinkerou thinkerou merged commit 3abc96e into gin-gonic:master Dec 1, 2019
ThomasObenaus pushed a commit to ThomasObenaus/gin that referenced this pull request Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wildcard conflict should panic but doesn't
2 participants