Fixes lint issues, adds profile script

This commit is contained in:
Tom Hudson 2016-06-20 00:20:27 +01:00
parent 101119d3e5
commit 236df730ed
5 changed files with 24 additions and 2 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
cpu.out
linkheader.test

View File

@ -63,7 +63,7 @@ func (l Links) FilterByRel(r string) Links {
// String returns the string representation of multiple Links // String returns the string representation of multiple Links
// for use in HTTP responses etc // for use in HTTP responses etc
func (l Links) String() string { func (l Links) String() string {
strs := make([]string, 0) var strs []string
for _, link := range l { for _, link := range l {
strs = append(strs, link.String()) strs = append(strs, link.String())
} }

View File

@ -145,3 +145,14 @@ func TestLinksToString(t *testing.T) {
t.Errorf("Want `%s`, have `%s`", want, have) t.Errorf("Want `%s`, have `%s`", want, have)
} }
} }
func BenchmarkParse(b *testing.B) {
header := "<https://api.github.com/user/9287/repos?page=3&per_page=100>; rel=\"next\", " +
"<https://api.github.com/user/9287/repos?page=1&per_page=100>; rel=\"prev\"; pet=\"cat\", " +
"<https://api.github.com/user/9287/repos?page=5&per_page=100>; rel=\"last\""
for i := 0; i < b.N; i++ {
_ = Parse(header)
}
}

View File

@ -1,4 +1,6 @@
#!/bin/sh #!/bin/sh
PROJDIR=$(cd `dirname $0`/.. && pwd) PROJDIR=$(cd `dirname $0`/.. && pwd)
cd ${PROJDIR} && gometalinter cd ${PROJDIR}
go get
gometalinter

7
script/profile Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
set -e
PROJDIR=$(cd `dirname $0`/.. && pwd)
cd ${PROJDIR}
go test -bench . -benchmem -cpuprofile cpu.out
go tool pprof linkheader.test cpu.out