Made it easier to do some profiling on the code.
This commit is contained in:
parent
a9964163c1
commit
b8d99972bb
2
Makefile
2
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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 < <path to TOML-file>\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 {
|
||||
|
|
BIN
parse2/parse2
BIN
parse2/parse2
Binary file not shown.
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue