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

feat: improve get post data. #1920

Merged
merged 1 commit into from
Jun 2, 2019
Merged

Conversation

appleboy
Copy link
Member

benchmark program:

func BenchmarkGetPostFormArrayNew(b *testing.B) {
	c, _ := CreateTestContext(httptest.NewRecorder())
	c.Request = createMultipartRequest()

	var obj struct {
		Foo          string    `form:"foo"`
		Bar          string    `form:"bar"`
		BarAsInt     int       `form:"bar"`
		Array        []string  `form:"array"`
		ID           string    `form:"id"`
		TimeLocal    time.Time `form:"time_local" time_format:"02/01/2006 15:04"`
		TimeUTC      time.Time `form:"time_utc" time_format:"02/01/2006 15:04" time_utc:"1"`
		TimeLocation time.Time `form:"time_location" time_format:"02/01/2006 15:04" time_location:"Asia/Tokyo"`
		BlankTime    time.Time `form:"blank_time" time_format:"02/01/2006 15:04"`
	}
	c.Bind(&obj)

	for i := 0; i < b.N; i++ {
		c.GetPostFormArray("array")
	}
}

result:

$ go test -benchmem -run=^$ github.com/gin-gonic/gin -bench ^BenchmarkGetPostFormArray
goos: darwin
goarch: amd64
pkg: github.com/gin-gonic/gin
BenchmarkGetPostFormArrayOld-4          50000000                32.4 ns/op             0 B/op          0 allocs/op
BenchmarkGetPostFormArrayNew-4          50000000                22.3 ns/op             0 B/op          0 allocs/op
PASS
ok      github.com/gin-gonic/gin        2.847s

@appleboy appleboy added this to the 1.5 milestone May 31, 2019
@codecov
Copy link

codecov bot commented May 31, 2019

Codecov Report

Merging #1920 into master will increase coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1920      +/-   ##
==========================================
+ Coverage   98.75%   98.75%   +<.01%     
==========================================
  Files          38       38              
  Lines        2167     2172       +5     
==========================================
+ Hits         2140     2145       +5     
  Misses         15       15              
  Partials       12       12
Impacted Files Coverage Δ
context.go 98.42% <80%> (+0.01%) ⬆️

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 4b6df41...ca6517d. Read the comment docs.

@thinkerou thinkerou merged commit 08b52e5 into gin-gonic:master Jun 2, 2019
@appleboy appleboy deleted the performance branch June 2, 2019 15:14
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.

2 participants