From bf7b693cb865eb0694d79c063389df42e957678a Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Wed, 24 Jul 2019 22:42:54 +0000 Subject: [PATCH] Lowering the number of forks required. --- ast/ast.go | 4 ++-- cmd/burntsushi-tester/Makefile | 16 ++++++++++++++-- parse/keyvaluepair.go | 2 +- parse/value_array.go | 2 +- parse/value_datetime.go | 2 +- parse/value_number.go | 2 +- parse/value_string.go | 22 +++++++++++----------- parse/value_table.go | 6 +++--- parse2/profile-sushi.sh | 2 +- parse2/profile.sh | 2 +- 10 files changed, 36 insertions(+), 24 deletions(-) diff --git a/ast/ast.go b/ast/ast.go index 379c0c7..cf3b86b 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -133,8 +133,8 @@ const ( TypeImplicitTable ValueType = "implicit-table" ) -// SetKeyValuePair is used to set a key and an accompanying value in the -// currently active TOML table of the TOML Document. +// SetKeyValuePair sets a key and an accompanying value in the currently active +// TOML table of the TOML Document. func (doc *Document) SetKeyValuePair(key Key, value *Value) error { // First make sure the table structure for storing the value exists. node, lastKeyPart, err := doc.makeTablePath(key) diff --git a/cmd/burntsushi-tester/Makefile b/cmd/burntsushi-tester/Makefile index 53625fb..983acc2 100644 --- a/cmd/burntsushi-tester/Makefile +++ b/cmd/burntsushi-tester/Makefile @@ -1,3 +1,5 @@ +PROFILE_COUNT=100 + b: go build mv burntsushi-tester B @@ -21,20 +23,30 @@ profile: profile-a profile-b test-a: numactl --physcpubind=+1 bash -c "time ./A < testfile.toml" +test2-a: + numactl --physcpubind=+1 bash -c "time ./A < testfile2.toml" + profile-a: - numactl --physcpubind=+1 bash -c "./A -p 250 < testfile.toml" + numactl --physcpubind=+1 bash -c "./A -p ${PROFILE_COUNT} < testfile.toml" test-b: numactl --physcpubind=+2 bash -c "time ./B < testfile.toml" +test2-b: + numactl --physcpubind=+2 bash -c "time ./B < testfile2.toml" + profile-b: - numactl --physcpubind=+2 bash -c "./B -p 250 < testfile.toml" + numactl --physcpubind=+2 bash -c "./B -p ${PROFILE_COUNT} < testfile.toml" test-sushi: numactl --physcpubind=+3 bash -c "time ${GOPATH}/bin/toml-test-decoder < testfile.toml" +test2-sushi: + + numactl --physcpubind=+3 bash -c "time ${GOPATH}/bin/toml-test-decoder < testfile2.toml" + test-sushi-a: diff --git a/parse/keyvaluepair.go b/parse/keyvaluepair.go index cd842e6..345d3e7 100644 --- a/parse/keyvaluepair.go +++ b/parse/keyvaluepair.go @@ -48,7 +48,7 @@ func (t *parser) startKeyValuePair(p *parse.API) { if value, ok := t.parseValue(p); ok { err := t.doc.SetKeyValuePair(key, value) if err != nil { - p.Error("%s", err) + p.SetError("%s", err) } else if !p.Accept(endOfLineOrComment) { p.Expected("end of line") } diff --git a/parse/value_array.go b/parse/value_array.go index 0bc37c1..2ee1055 100644 --- a/parse/value_array.go +++ b/parse/value_array.go @@ -63,7 +63,7 @@ func (t *parser) parseArray(p *parse.API) (*ast.Value, bool) { // considered the same type, and so should arrays with different element types). // This constraint is checked by ast.Array.Append(). if err := a.Append(value); err != nil { - p.Error(err.Error()) + p.SetError(err.Error()) return nil, false } diff --git a/parse/value_datetime.go b/parse/value_datetime.go index 0201fa2..a767187 100644 --- a/parse/value_datetime.go +++ b/parse/value_datetime.go @@ -99,7 +99,7 @@ func (t *parser) parseDateTime(p *parse.API) (*ast.Value, bool) { } value, err := time.Parse(layout, p.Result.String()) if err != nil { - p.Error("invalid date/time value %s: %s", p.Result.String(), err) + p.SetError("invalid date/time value %s: %s", p.Result.String(), err) return nil, false } diff --git a/parse/value_number.go b/parse/value_number.go index 2dbf4bc..602d949 100644 --- a/parse/value_number.go +++ b/parse/value_number.go @@ -107,6 +107,6 @@ func (t *parser) parseIntegerStartingWithZero(p *parse.API) (*ast.Value, bool) { if err == nil { return ast.NewValue(ast.TypeInteger, value), true } - p.Error("invalid integer value 0%s: %s", p.Result.String(), err) + p.SetError("invalid integer value 0%s: %s", p.Result.String(), err) return nil, false } diff --git a/parse/value_string.go b/parse/value_string.go index ea0a51c..5a2860e 100644 --- a/parse/value_string.go +++ b/parse/value_string.go @@ -104,19 +104,19 @@ func (t *parser) parseBasicString(name string, p *parse.API) (string, bool) { for { switch { case p.PeekWithResult(controlCharacter): - p.Error("invalid character in %s: %q (must be escaped)", name, p.Result.Runes[0]) + p.SetError("invalid character in %s: %q (must be escaped)", name, p.Result.Runes[0]) return sb.String(), false case p.Accept(validEscape): if !appendEscapedRune(p, sb) { return sb.String(), false } case p.Peek(a.Backslash): - p.Error("invalid escape sequence") + p.SetError("invalid escape sequence") return sb.String(), false case p.Accept(basicStringDelimiter): return sb.String(), true case p.Peek(a.InvalidRune): - p.Error("invalid UTF8 rune") + p.SetError("invalid UTF8 rune") return sb.String(), false case p.Accept(a.ValidRune): sb.WriteString(p.Result.String()) @@ -147,10 +147,10 @@ func (t *parser) parseLiteralString(name string, p *parse.API) (string, bool) { case p.Accept(a.Tab): sb.WriteString("\t") case p.PeekWithResult(controlCharacter): - p.Error("invalid character in %s: %q (no control chars allowed, except for tab)", name, p.Result.Runes[0]) + p.SetError("invalid character in %s: %q (no control chars allowed, except for tab)", name, p.Result.Runes[0]) return sb.String(), false case p.Peek(a.InvalidRune): - p.Error("invalid UTF8 rune") + p.SetError("invalid UTF8 rune") return sb.String(), false case p.Accept(a.ValidRune): sb.WriteString(p.Result.String()) @@ -195,7 +195,7 @@ func (t *parser) parseMultiLineBasicString(p *parse.API) (string, bool) { case p.Accept(newline): sb.WriteString("\n") case p.PeekWithResult(controlCharacter): - p.Error("invalid character in multi-line basic string: %q (must be escaped)", p.Result.Runes[0]) + p.SetError("invalid character in multi-line basic string: %q (must be escaped)", p.Result.Runes[0]) return sb.String(), false case p.Accept(validEscape): if !appendEscapedRune(p, sb) { @@ -204,14 +204,14 @@ func (t *parser) parseMultiLineBasicString(p *parse.API) (string, bool) { case p.Accept(lineEndingBackslash): // NOOP, the line-ending backslash sequence is skipped. case p.Peek(a.Backslash): - p.Error("invalid escape sequence") + p.SetError("invalid escape sequence") return sb.String(), false case p.Accept(closingMultiLineBasicString): return sb.String(), true case p.Accept(a.ValidRune): sb.WriteString(p.Result.String()) case p.Peek(a.InvalidRune): - p.Error("invalid UTF8 rune") + p.SetError("invalid UTF8 rune") return sb.String(), false default: p.Expected("closing three quotation marks") @@ -243,7 +243,7 @@ func appendEscapedRune(p *parse.API, sb *strings.Builder) bool { val, _ := strconv.ParseUint(hex, 16, 32) // hex format already validated by parser r := rune(val) if !utf8.ValidRune(r) { - p.Error(fmt.Sprintf("invalid UTF8 escape '%s'", s)) + p.SetError(fmt.Sprintf("invalid UTF8 escape '%s'", s)) return false } sb.WriteRune(r) @@ -279,12 +279,12 @@ func (t *parser) parseMultiLineLiteralString(p *parse.API) (string, bool) { case p.Accept(newline): sb.WriteString("\n") case p.PeekWithResult(controlCharacter): - p.Error("invalid character in literal string: %q (no control chars allowed, except for tab and newline)", p.Result.Runes[0]) + p.SetError("invalid character in literal string: %q (no control chars allowed, except for tab and newline)", p.Result.Runes[0]) return sb.String(), false case p.Accept(a.ValidRune): sb.WriteString(p.Result.String()) case p.Peek(a.InvalidRune): - p.Error("invalid UTF8 rune") + p.SetError("invalid UTF8 rune") return sb.String(), false default: p.Expected("closing three single quotes") diff --git a/parse/value_table.go b/parse/value_table.go index 3d0ff57..d24cd27 100644 --- a/parse/value_table.go +++ b/parse/value_table.go @@ -80,7 +80,7 @@ func (t *parser) startArrayOfTables(p *parse.API) { return } if err := t.doc.OpenArrayOfTables(key); err != nil { - p.Error("%s", err) + p.SetError("%s", err) return } p.Handle(t.startDocument) @@ -136,7 +136,7 @@ func (t *parser) startPlainTable(p *parse.API) { return } if err := t.doc.OpenTable(key); err != nil { - p.Error("%s", err) + p.SetError("%s", err) return } p.Handle(t.startDocument) @@ -188,7 +188,7 @@ func (t *parser) parseInlineTable(p *parse.API) (*ast.Value, bool) { } err := subdoc.doc.SetKeyValuePair(key, value) if err != nil { - p.Error("%s", err) + p.SetError("%s", err) return nil, false } diff --git a/parse2/profile-sushi.sh b/parse2/profile-sushi.sh index 130fc44..986a988 100755 --- a/parse2/profile-sushi.sh +++ b/parse2/profile-sushi.sh @@ -6,7 +6,7 @@ FILE=normal.toml ITER=10000 cd ../cmd/burntsushi-tester -go build +go build -gcflags=all=-l cd ../../parse2 ppfile=`cat $FILE | ../cmd/burntsushi-tester/burntsushi-tester -p $ITER 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 eef0679..caf8928 100755 --- a/parse2/profile.sh +++ b/parse2/profile.sh @@ -11,6 +11,6 @@ #go build -gcflags=all=-l -v go build -v -ppfile=`cat long.toml | ./parse2 -p 25 2>&1 | grep "profiling enabled" | cut -d, -f2` +ppfile=`cat long.toml | ./parse2 -p 50 2>&1 | grep "profiling enabled" | cut -d, -f2` go tool pprof -http 0.0.0.0:8888 ./parse2 $ppfile