diff --git a/.travis.yml b/.travis.yml index 77049dc..1f8b41f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,9 @@ matrix: - go: tip fast_finish: true script: + - if [ -n "$(go fmt ./...)" ]; then exit 1; fi - ./test.sh + - ./benchmark.sh $TRAVIS_BRANCH https://github.com/$TRAVIS_REPO_SLUG.git before_install: - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls diff --git a/benchmark.sh b/benchmark.sh new file mode 100755 index 0000000..cf1dabb --- /dev/null +++ b/benchmark.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +reference_ref=${1:-master} +reference_git=${2:-.} + +if ! `hash benchstat 2>/dev/null`; then + echo "Installing benchstat" + go get golang.org/x/perf/cmd/benchstat + go install golang.org/x/perf/cmd/benchstat +fi + +tempdir=`mktemp -d /tmp/go-toml-benchmark-XXXXXX` +ref_tempdir="${tempdir}/ref" +ref_benchmark="${ref_tempdir}/benchmark-${reference_ref}.txt" +local_benchmark="`pwd`/benchmark-local.txt" + +echo "=== ${reference_ref} (${ref_tempdir})" +git clone ${reference_git} ${ref_tempdir} >/dev/null 2>/dev/null +pushd ${ref_tempdir} >/dev/null +git checkout ${reference_ref} >/dev/null 2>/dev/null +go test -bench=. -benchmem | tee ${ref_benchmark} +popd >/dev/null + +echo "" +echo "=== local" +go test -bench=. -benchmem | tee ${local_benchmark} + +echo "" +echo "=== diff" +benchstat -delta-test=none ${ref_benchmark} ${local_benchmark} \ No newline at end of file diff --git a/query/lexer.go b/query/lexer.go index 6336d52..2dc3194 100644 --- a/query/lexer.go +++ b/query/lexer.go @@ -7,10 +7,10 @@ package query import ( "fmt" + "github.com/pelletier/go-toml" "strconv" "strings" "unicode/utf8" - "github.com/pelletier/go-toml" ) // Lexer state function @@ -55,7 +55,7 @@ func (l *queryLexer) nextStart() { func (l *queryLexer) emit(t tokenType) { l.tokens <- token{ - Position: toml.Position{Line:l.line, Col:l.col}, + Position: toml.Position{Line: l.line, Col: l.col}, typ: t, val: l.input[l.start:l.pos], } @@ -64,7 +64,7 @@ func (l *queryLexer) emit(t tokenType) { func (l *queryLexer) emitWithValue(t tokenType, value string) { l.tokens <- token{ - Position: toml.Position{Line:l.line, Col:l.col}, + Position: toml.Position{Line: l.line, Col: l.col}, typ: t, val: value, } @@ -92,7 +92,7 @@ func (l *queryLexer) backup() { func (l *queryLexer) errorf(format string, args ...interface{}) queryLexStateFn { l.tokens <- token{ - Position: toml.Position{Line:l.line, Col:l.col}, + Position: toml.Position{Line: l.line, Col: l.col}, typ: tokenError, val: fmt.Sprintf(format, args...), } diff --git a/query/lexer_test.go b/query/lexer_test.go index e2b733a..8ce0501 100644 --- a/query/lexer_test.go +++ b/query/lexer_test.go @@ -1,8 +1,8 @@ package query import ( - "testing" "github.com/pelletier/go-toml" + "testing" ) func testQLFlow(t *testing.T, input string, expectedFlow []token) { diff --git a/query/match_test.go b/query/match_test.go index 567b11c..429b8f6 100644 --- a/query/match_test.go +++ b/query/match_test.go @@ -2,8 +2,8 @@ package query import ( "fmt" - "testing" "github.com/pelletier/go-toml" + "testing" ) // dump path tree to a string diff --git a/query/parser_test.go b/query/parser_test.go index b1d0a3e..473896a 100644 --- a/query/parser_test.go +++ b/query/parser_test.go @@ -2,12 +2,12 @@ package query import ( "fmt" + "github.com/pelletier/go-toml" "io/ioutil" "sort" "strings" "testing" "time" - "github.com/pelletier/go-toml" ) type queryTestNode struct { diff --git a/query/tokens.go b/query/tokens.go index 429e289..9ae579d 100644 --- a/query/tokens.go +++ b/query/tokens.go @@ -1,10 +1,10 @@ package query import ( -"fmt" -"strconv" -"unicode" + "fmt" "github.com/pelletier/go-toml" + "strconv" + "unicode" ) // Define tokens @@ -104,4 +104,3 @@ func isHexDigit(r rune) bool { (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F') } -