diff --git a/parse2/grammar.go b/parse2/grammar.go index 4a6dedd..50fe2ff 100644 --- a/parse2/grammar.go +++ b/parse2/grammar.go @@ -38,14 +38,21 @@ func main() { 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) + 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)) } + duration := time.Since(start) p.Stop() + fmt.Printf("\n") fmt.Println("Duration:", duration) return diff --git a/parse2/grammar_test.go b/parse2/grammar_test.go new file mode 100644 index 0000000..5598167 --- /dev/null +++ b/parse2/grammar_test.go @@ -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) + } +} diff --git a/parse2/x b/parse2/normal.toml similarity index 100% rename from parse2/x rename to parse2/normal.toml diff --git a/parse2/parse2 b/parse2/parse2 index 85fc2d1..d841bc8 100755 Binary files a/parse2/parse2 and b/parse2/parse2 differ diff --git a/parse2/performance_timings.txt b/parse2/performance_timings.txt index ebcc927..f6ab3c2 100644 --- a/parse2/performance_timings.txt +++ b/parse2/performance_timings.txt @@ -25,4 +25,13 @@ 185.826552ms qa-long-loads-of-comments.toml 0.190 time ./parse2 < long.toml -0.005 time ./parse2 < x \ No newline at end of file +0.005 time ./parse2 < x + +--- new benchmark tests +NO CURSOR UPDATES BASELINE + 0.264 (test-sushi) +274544444 256706465 +2259506 2118384 +23911 22624 + + diff --git a/parse2/short.toml b/parse2/short.toml index 413bdd8..4f2c2c4 100644 --- a/parse2/short.toml +++ b/parse2/short.toml @@ -1 +1,2 @@ +############################################################# key={key={}}