Various small updates, related to speed improvements.

This commit is contained in:
Maurice Makaay 2019-07-18 00:23:14 +00:00
parent c37404875d
commit 96a72c4c48
10 changed files with 22986 additions and 45 deletions

3
.gitignore vendored
View File

@ -1,5 +1,8 @@
# Build output
cmd/burntsushi-tester/burntsushi-tester
cmd/burntsushi-tester/A
cmd/burntsushi-tester/B
parse2/parse2
# ---> Vim
# Swap

View File

@ -0,0 +1,22 @@
a:
go build
mv burntsushi-tester A
b:
go build
mv burntsushi-tester B
test: test-a test-b test-sushi
test-a:
numactl --physcpubind=+1 bash -c "time ./A < testfile.toml"
test-b:
numactl --physcpubind=+2 bash -c "time ./B < testfile.toml"
test-sushi:
numactl --physcpubind=+3 bash -c "time ~/go-workspace/bin/toml-test-decoder < testfile.toml"

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ func TestComment(t *testing.T) {
{``, `{}`, ``},
{`#`, `{}`, ``},
{`# `, `{}`, ``},
{`# with data`, `{}`, ``},
{`# aaaaaa`, `{}`, ``},
{"# ending in EOL & EOF\r\n", `{}`, ``},
{`# \xxx/ \u can't escape/`, `{}`, ``},
{"# \tlexe\r accepts embedded ca\r\riage \returns\r\n", `{}`, ``},

View File

@ -11,7 +11,7 @@ var (
c, a, m, tok = tokenize.C, tokenize.A, tokenize.M, tokenize.T
// Whitespace means tab (0x09) or space (0x20).
// The matches the blanks as defined by parsekit.
// This matches the blanks as defined by parsekit.
whitespace = a.Blanks.Optional()
@ -28,7 +28,7 @@ var (
// A '#' hash symbol marks the rest of the line as a comment.
// All characters up to the end of the line are included in the comment.
comment = c.Seq(a.Hash, a.UntilEndOfLine.Optional())
comment = c.Seq(a.Hash, m.DropUntilEndOfLine)
optionalComment = comment.Optional()
endOfLineOrComment = c.Seq(whitespace, optionalComment, a.EndOfLine)

View File

@ -1,47 +1,269 @@
package main
import (
"io/ioutil"
"testing"
)
func BenchmarkLongToml(b *testing.B) {
benchmarkFile(b, "long.toml")
// func BenchmarkLongToml(b *testing.B) {
// benchmarkFile(b, "long.toml")
// }
// func BenchmarkNormalToml(b *testing.B) {
// benchmarkFile(b, "normal.toml")
// }
// func BenchmarkShortToml(b *testing.B) {
// benchmarkFile(b, "short.toml")
// }
// func benchmarkFile(b *testing.B, file string) {
// toml := BuildGrammar()
// inputBytes, err := ioutil.ReadFile(file)
// if err != nil {
// b.Fatalf("Cannot read input file (%s): %s", file, err)
// }
// inputStr := string(inputBytes)
// for i := 0; i < b.N; i++ {
// _, err := toml.Match(inputStr)
// if err != nil {
// b.Fatalf("Error in parsing TOML input: %s\n", err)
// }
// }
// }
// func BenchmarkReadArrayOfInt(b *testing.B) {
// type F [10]int
// arr := make([]F, 10000)
// for i := 0; i < 10000; i++ {
// arr[i] = [10]int{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// }
// for i := 0; i < b.N; i++ {
// for x := 0; x < 10000; x++ {
// val := arr[x][0] + arr[x][1] + arr[x][2] + arr[x][3] + arr[x][4] + arr[x][5] + arr[x][6] + arr[x][7] + arr[x][8] + arr[x][9]
// val += 0
// }
// }
// }
// func BenchmarkWriteArrayOfInt(b *testing.B) {
// type F [10]int
// for i := 0; i < b.N; i++ {
// arr := make([]F, 10000)
// for i := 0; i < 10000; i++ {
// arr[i] = [10]int{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// }
// }
// }
// func BenchmarkWriteRandomArrayOfInt(b *testing.B) {
// type F [10]int
// for i := 0; i < b.N; i++ {
// arr := make([]F, 10000)
// for i := 0; i < 10000; i++ {
// arr[i] = [10]int{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// arr[i][0] = 666
// arr[i][1] = 666
// arr[i][2] = 666
// arr[i][3] = 666
// arr[i][4] = 666
// arr[i][5] = 666
// arr[i][6] = 666
// arr[i][7] = 666
// arr[i][8] = 666
// arr[i][9] = 666
// }
// }
// }
func BenchmarkReadArrayOfStructs(b *testing.B) {
type F struct {
A int
B int
C int
D int
E int
F int
G int
H int
I int
J int
}
arr := make([]F, 10000)
for i := 0; i < 10000; i++ {
arr[i] = F{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
}
func BenchmarkNormalToml(b *testing.B) {
benchmarkFile(b, "normal.toml")
}
func BenchmarkShortToml(b *testing.B) {
benchmarkFile(b, "short.toml")
}
func benchmarkFile(b *testing.B, file string) {
toml := BuildGrammar()
inputBytes, err := ioutil.ReadFile(file)
if err != nil {
b.Fatalf("Cannot read input file (%s): %s", file, err)
}
inputStr := string(inputBytes)
for i := 0; i < b.N; i++ {
_, err := toml.Match(inputStr)
if err != nil {
b.Fatalf("Error in parsing TOML input: %s\n", err)
for x := 0; x < 10000; x++ {
val := arr[x].A + arr[x].B + arr[x].C + arr[x].D + arr[x].E + arr[x].F + arr[x].G + arr[x].H + arr[x].I + arr[x].J
val += 0
}
}
}
func TestBugfix(t *testing.T) {
toml := BuildGrammar()
inputBytes, err := ioutil.ReadFile("short.toml")
if err != nil {
t.Fatalf("Cannot read input file (%s): %s", "short.toml", err)
func BenchmarkReadStructOfArrays(b *testing.B) {
type F struct {
A []int
B []int
C []int
D []int
E []int
F []int
G []int
H []int
I []int
J []int
}
s := F{}
for i := 0; i < 10000; i++ {
s.A = append(s.A, 1)
s.B = append(s.B, 1)
s.C = append(s.C, 1)
s.D = append(s.D, 1)
s.E = append(s.E, 1)
s.F = append(s.F, 1)
s.G = append(s.G, 1)
s.H = append(s.H, 1)
s.I = append(s.I, 1)
s.J = append(s.J, 1)
}
inputStr := string(inputBytes)
_, err = toml.Match(inputStr)
if err != nil {
t.Fatalf("Error in parsing TOML input: %s\n", err)
for i := 0; i < b.N; i++ {
for x := 0; x < 10000; x++ {
val := s.A[x] + s.B[x] + s.C[x] + s.D[x] + s.E[x] + s.F[x] + s.G[x] + s.H[x] + s.I[x] + s.J[x]
val += 0
}
}
}
// func BenchmarkWriteArrayOfStructs(b *testing.B) {
// type F struct {
// A int
// B int
// C int
// D int
// E int
// F int
// G int
// H int
// I int
// J int
// }
// for i := 0; i < b.N; i++ {
// arr := make([]F, 10000)
// for i := 0; i < 10000; i++ {
// arr[i] = F{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// }
// }
// }
// func BenchmarkWriteRandomArrayOfStructs(b *testing.B) {
// type F struct {
// A int
// B int
// C int
// D int
// E int
// F int
// G int
// H int
// I int
// J int
// }
// for i := 0; i < b.N; i++ {
// arr := make([]F, 10000)
// for i := 0; i < 10000; i++ {
// arr[i] = F{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// arr[i].A = 666
// arr[i].B = 666
// arr[i].C = 666
// arr[i].D = 666
// arr[i].E = 666
// arr[i].F = 666
// arr[i].G = 666
// arr[i].H = 666
// arr[i].I = 666
// arr[i].J = 666
// }
// }
// }
// func BenchmarkReadMapOfStructs(b *testing.B) {
// type F struct {
// A int
// B int
// C int
// D int
// E int
// F int
// G int
// H int
// I int
// J int
// }
// fMap := make(map[int]F)
// for i := 0; i < 10000; i++ {
// fMap[i] = F{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// }
// for i := 0; i < b.N; i++ {
// for x := 0; x < 10000; x++ {
// val := fMap[x].A + fMap[x].B + fMap[x].C + fMap[x].D + fMap[x].E + fMap[x].F + fMap[x].G + fMap[x].H + fMap[x].I + fMap[x].J
// val += 0
// }
// }
// }
// func BenchmarkWriteMapOfStructs(b *testing.B) {
// type F struct {
// A int
// B int
// C int
// D int
// E int
// F int
// G int
// H int
// I int
// J int
// }
// for i := 0; i < b.N; i++ {
// fMap := make(map[int]F)
// for i := 0; i < 10000; i++ {
// fMap[i] = F{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// }
// }
// }
// func BenchmarkWriteRandomMapOfStructs(b *testing.B) {
// type F struct {
// A int
// B int
// C int
// D int
// E int
// F int
// G int
// H int
// I int
// J int
// }
// for i := 0; i < b.N; i++ {
// fMap := make(map[int]F)
// for i := 0; i < 10000; i++ {
// fMap[i] = F{i, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// s := fMap[i]
// s.A = 666
// s.B = 666
// s.C = 666
// s.D = 666
// s.E = 666
// s.F = 666
// s.G = 666
// s.H = 666
// s.I = 666
// s.J = 666
// }
// }
// }

Binary file not shown.

View File

@ -6,16 +6,16 @@ $(cd ../cmd/burntsushi-tester/; go build)
DURATION=`./parse2 -p 10 < long.toml 2>&1 | grep Duration | awk '{print $2}'`
echo "$DURATION parse2 10 iteration profiling of long.toml"
DURATION=`./parse2 -p 1000 < x 2>&1 | grep Duration | awk '{print $2}'`
echo "$DURATION parse2 1000 iteration profiling of x"
DURATION=`./parse2 -p 1000 < normal.toml 2>&1 | grep Duration | awk '{print $2}'`
echo "$DURATION parse2 1000 iteration profiling of normal.toml"
echo ""
DURATION=`../cmd/burntsushi-tester/burntsushi-tester -p 10 < long.toml 2>&1 | grep Duration | awk '{print $2}'`
echo "$DURATION burntsushi-tester 10 iteration profiling of long.toml"
DURATION=`../cmd/burntsushi-tester/burntsushi-tester -p 1000 < x 2>&1 | grep Duration | awk '{print $2}'`
echo "$DURATION burntsushi-tester 1000 iteration profiling of x"
DURATION=`../cmd/burntsushi-tester/burntsushi-tester -p 1000 < normal.toml 2>&1 | grep Duration | awk '{print $2}'`
echo "$DURATION burntsushi-tester 1000 iteration profiling of normal.toml"
echo ""

View File

@ -1,17 +1,13 @@
#!/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`
#FILE=short.toml
FILE=normal.toml
#FILE=long.toml
ITER=10000
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`
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

View File

@ -1,2 +1,2 @@
#############################################################
#
key={key={}}