From 236df730ed7334edb33cb10ba79407491fb4e147 Mon Sep 17 00:00:00 2001 From: Tom Hudson Date: Mon, 20 Jun 2016 00:20:27 +0100 Subject: [PATCH] Fixes lint issues, adds profile script --- .gitignore | 2 ++ main.go | 2 +- main_test.go | 11 +++++++++++ script/lint | 4 +++- script/profile | 7 +++++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100755 script/profile 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