Skip to content
Myr

form_mapping_benchmark_test.go

This file

Path

binding/form_mapping_benchmark_test.go

67 lines · 1.4 KiB · Go

Last changed by

refactor: use b.Loop() to simplify the code and improve performance (#4432)efckingbefore adoptiona85ef5c

History of this file

Take it

The walk stopped after 200 commits: lines older than cf32d2d point at it.

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

lines 1–33why, one step back
1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package binding67import (8 "testing"9 "time"1011 "github.com/stretchr/testify/assert"12)1314var form = map[string][]string{15 "name": {"mike"},16 "friends": {"anna", "nicole"},17 "id_number": {"12345678"},18 "id_date": {"2018-01-20"},19}2021type structFull struct {22 Name string `form:"name"`23 Age int `form:"age,default=25"`24 Friends []string `form:"friends"`25 ID *struct {26 Number string `form:"id_number"`27 DateOfIssue time.Time `form:"id_date" time_format:"2006-01-02" time_utc:"true"`28 }29 Nationality *string `form:"nationality"`30}3132func BenchmarkMapFormFull(b *testing.B) {33 var s structFull

refactor: use b.Loop() to simplify the code and improve performance (#4432)efckingbefore adoptiona85ef5c

line 34why, one step back
34 for b.Loop() {

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

lines 35–56why, one step back
35 err := mapForm(&s, form)
36 if err != nil {37 b.Fatalf("Error on a form mapping")38 }39 }40 b.StopTimer()4142 t := b43 assert.Equal(t, "mike", s.Name)44 assert.Equal(t, 25, s.Age)45 assert.Equal(t, []string{"anna", "nicole"}, s.Friends)46 assert.Equal(t, "12345678", s.ID.Number)47 assert.Equal(t, time.Date(2018, 1, 20, 0, 0, 0, 0, time.UTC), s.ID.DateOfIssue)48 assert.Nil(t, s.Nationality)49}5051type structName struct {52 Name string `form:"name"`53}5455func BenchmarkMapFormName(b *testing.B) {56 var s structName

refactor: use b.Loop() to simplify the code and improve performance (#4432)efckingbefore adoptiona85ef5c

line 57why, one step back
57 for b.Loop() {

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

lines 58–67why, one step back
58 err := mapForm(&s, form)
59 if err != nil {60 b.Fatalf("Error on a form mapping")61 }62 }63 b.StopTimer()6465 t := b66 assert.Equal(t, "mike", s.Name)67}