Some changes due to the performance improvements in parsekit.

This commit is contained in:
Maurice Makaay 2019-07-16 06:22:29 +00:00
parent 2fb6a5fd34
commit c37404875d
6 changed files with 65 additions and 1 deletions

View File

@ -38,14 +38,21 @@ func main() {
fmt.Println("Profiling ...") fmt.Println("Profiling ...")
inputBytes, _ := ioutil.ReadAll(os.Stdin) inputBytes, _ := ioutil.ReadAll(os.Stdin)
inputStr := string(inputBytes) inputStr := string(inputBytes)
p := profile.Start() p := profile.Start()
start := time.Now() start := time.Now()
for i := 0; i < *doProfile; i++ { for i := 0; i < *doProfile; i++ {
result, err = toml.Match(inputStr) result, err = toml.Match(inputStr)
if err != nil {
panic("Cannot profile, parsing input failed: " + err.Error())
}
fmt.Printf("cycle %d / %d, tokens=%d\r", i+1, *doProfile, len(result.Tokens)) fmt.Printf("cycle %d / %d, tokens=%d\r", i+1, *doProfile, len(result.Tokens))
} }
duration := time.Since(start) duration := time.Since(start)
p.Stop() p.Stop()
fmt.Printf("\n") fmt.Printf("\n")
fmt.Println("Duration:", duration) fmt.Println("Duration:", duration)
return return

47
parse2/grammar_test.go Normal file
View File

@ -0,0 +1,47 @@
package main
import (
"io/ioutil"
"testing"
)
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 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)
}
inputStr := string(inputBytes)
_, err = toml.Match(inputStr)
if err != nil {
t.Fatalf("Error in parsing TOML input: %s\n", err)
}
}

Binary file not shown.

View File

@ -25,4 +25,13 @@
185.826552ms qa-long-loads-of-comments.toml 185.826552ms qa-long-loads-of-comments.toml
0.190 time ./parse2 < long.toml 0.190 time ./parse2 < long.toml
0.005 time ./parse2 < x 0.005 time ./parse2 < x
--- new benchmark tests
NO CURSOR UPDATES BASELINE
0.264 (test-sushi)
274544444 256706465
2259506 2118384
23911 22624

View File

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