diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a00dde --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cpu.out +linkheader.test diff --git a/main.go b/main.go index 2a82a13..ce3b24a 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ func (l Links) FilterByRel(r string) Links { // String returns the string representation of multiple Links // for use in HTTP responses etc func (l Links) String() string { - strs := make([]string, 0) + var strs []string for _, link := range l { strs = append(strs, link.String()) } diff --git a/main_test.go b/main_test.go index 7b7ac77..6c8a4a0 100644 --- a/main_test.go +++ b/main_test.go @@ -145,3 +145,14 @@ func TestLinksToString(t *testing.T) { t.Errorf("Want `%s`, have `%s`", want, have) } } + +func BenchmarkParse(b *testing.B) { + + header := "; rel=\"next\", " + + "; rel=\"prev\"; pet=\"cat\", " + + "; rel=\"last\"" + + for i := 0; i < b.N; i++ { + _ = Parse(header) + } +} diff --git a/script/lint b/script/lint index 82bd64c..dfed93a 100755 --- a/script/lint +++ b/script/lint @@ -1,4 +1,6 @@ #!/bin/sh PROJDIR=$(cd `dirname $0`/.. && pwd) -cd ${PROJDIR} && gometalinter +cd ${PROJDIR} +go get +gometalinter diff --git a/script/profile b/script/profile new file mode 100755 index 0000000..f5b92ce --- /dev/null +++ b/script/profile @@ -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