diff --git a/Makefile b/Makefile index 97f73f5..c211f77 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,4 @@ test: test-sushi: @(cd cmd/burntsushi-tester; go build) @echo -n "BurntSushi tests: " - @(cd cmd/burntsushi-tester && ${GOPATH}/bin/toml-test ./burntsushi-tester) + @(/bin/bash -c "time ${GOPATH}/bin/toml-test ./cmd/burntsushi-tester/burntsushi-tester") diff --git a/cmd/burntsushi-tester/main.go b/cmd/burntsushi-tester/main.go index 990c77b..0161db2 100644 --- a/cmd/burntsushi-tester/main.go +++ b/cmd/burntsushi-tester/main.go @@ -6,16 +6,20 @@ package main import ( "flag" "fmt" + "io/ioutil" "log" "os" "path" + "time" "git.makaay.nl/mauricem/go-toml/parse" + "github.com/pkg/profile" ) -func init() { - log.SetFlags(0) +var doProfile *int +func init() { + doProfile = flag.Int("p", 0, "Perform pprof profiling (value is number of run loops)") flag.Usage = usage flag.Parse() } @@ -28,11 +32,24 @@ func usage() { } func main() { - if flag.NArg() != 0 { - flag.Usage() + if *doProfile > 0 { + fmt.Println("Profiling ...") + inputBytes, _ := ioutil.ReadAll(os.Stdin) + inputStr := string(inputBytes) + p := profile.Start() + start := time.Now() + for i := 0; i < *doProfile; i++ { + parse.Run(inputStr) + fmt.Printf("cycle %d / %d\r", i+1, *doProfile) + } + duration := time.Since(start) + p.Stop() + fmt.Printf("\n") + fmt.Println("Duration:", duration) + return } - toml, err := parse.RunWithoutSanityChecks(os.Stdin) + toml, err := parse.Run(os.Stdin) if err != nil { log.Fatalf("Error decoding TOML: %s", err) } else { diff --git a/parse/parse.go b/parse/parse.go index 0f9141f..532de9c 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -57,11 +57,3 @@ func Run(input interface{}) (ast.Table, error) { err := parse.New(p.startDocument)(input) return p.doc.Root, err } - -// RunWithoutSanityChecks runs the TOML parser against the provided input data. -// The parsekit sanity checks are disabled during the parse run. -func RunWithoutSanityChecks(input interface{}) (ast.Table, error) { - p := newParser() - err := parse.New(p.startDocument)(input) - return p.doc.Root, err -} diff --git a/parse2/grammar.go b/parse2/grammar.go index d10496b..ac5a678 100644 --- a/parse2/grammar.go +++ b/parse2/grammar.go @@ -1,39 +1,57 @@ package main import ( + "flag" "fmt" "io/ioutil" "log" "math" "os" + "path" "time" "git.makaay.nl/mauricem/go-parsekit/tokenize" "github.com/pkg/profile" ) -const runProfiler = true +var doProfile *int + +func init() { + doProfile = flag.Int("p", 0, "Perform pprof profiling (value is number of run loops)") + flag.Usage = usage + flag.Parse() +} + +func usage() { + log.Printf("Usage: %s < \n", path.Base(os.Args[0])) + flag.PrintDefaults() + + os.Exit(1) +} func main() { - bytes, _ := ioutil.ReadAll(os.Stdin) - input := string(bytes) - toml := BuildGrammar() - var result *tokenize.Result var err error - if runProfiler { - t := profile.Start() //profile.CPUProfile) - for i := 0; i < 20; i++ { - fmt.Printf(".") - result, err = toml.Match(input) + if *doProfile > 0 { + fmt.Println("Profiling ...") + inputBytes, _ := ioutil.ReadAll(os.Stdin) + inputStr := string(inputBytes) + p := profile.Start() + start := time.Now() + for i := 0; i < *doProfile; i++ { + result, err = toml.Match(inputStr) + fmt.Printf("cycle %d / %d, tokens=%d\r", i+1, *doProfile, len(result.Tokens)) } - t.Stop() - } else { - result, err = toml.Match(input) + duration := time.Since(start) + fmt.Printf("\n") + fmt.Println("Duration:", duration) + p.Stop() + return } + result, err = toml.Match(os.Stdin) if err != nil { log.Fatalf("Error in parsing TOML: %s\n", err) } else { diff --git a/parse2/parse2 b/parse2/parse2 index 0d6afc8..fcce0a9 100755 Binary files a/parse2/parse2 and b/parse2/parse2 differ diff --git a/parse2/performance_timings.txt b/parse2/performance_timings.txt new file mode 100644 index 0000000..abc99c8 --- /dev/null +++ b/parse2/performance_timings.txt @@ -0,0 +1,12 @@ +0.004 burntsushi tester with x +1.347 burntsushi profile cycle 1000 with x +0.005 parse2 non-profile mode with x +1.850 parse2 profile cycle 1000 with x + +0.098 burntsushi with long.toml +0.950 burntsushi profile cycle 10 with long.toml +0.190 parse2 non-profile mode with long.toml +1.843 parse2 profile cycle 10 with long.toml + +0.213 parse test set +0.239 burntsushi test set \ No newline at end of file diff --git a/parse2/profile-sushi.sh b/parse2/profile-sushi.sh new file mode 100755 index 0000000..e55d9f8 --- /dev/null +++ b/parse2/profile-sushi.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#cd $GOPATH/src/git.makaay.nl/mauricem/go-toml/cmd/burntsushi-tester/ +#go build +#go install +#cd $GOPATH/src/git.makaay.nl/mauricem/go-toml/parse2 +#PPFILE=`cat long.toml | $GOPATH/bin/burntsushi-tester 2>&1 | grep "profiling enabled" | cut -d, -f2` +#echo $PPFILE + +#ppfile=` | ./parse2 2>&1 | grep "cpu profiling enabled" | cut -d, -f2` + +cd ../cmd/burntsushi-tester +go build +cd ../../parse2 +ppfile=`cat x | ../cmd/burntsushi-tester/burntsushi-tester -p 100 2>&1 | grep "profiling enabled" | cut -d, -f2` +go tool pprof -http 0.0.0.0:8888 ../cmd/burntsushi-tester/burntsushi-tester $ppfile + diff --git a/parse2/profile.sh b/parse2/profile.sh index aafb6bc..2961ac0 100755 --- a/parse2/profile.sh +++ b/parse2/profile.sh @@ -10,6 +10,6 @@ #ppfile=` | ./parse2 2>&1 | grep "cpu profiling enabled" | cut -d, -f2` go build -ppfile=`cat long.toml | time ./parse2 2>&1 | grep "profiling enabled" | cut -d, -f2` +ppfile=`cat long.toml | ./parse2 -p 10 2>&1 | grep "profiling enabled" | cut -d, -f2` go tool pprof -http 0.0.0.0:8888 ./parse2 $ppfile