diff --git a/benchmark.cfg b/benchmark.cfg new file mode 100644 index 0000000..499492e --- /dev/null +++ b/benchmark.cfg @@ -0,0 +1,24 @@ +# Global stuff +global = "global value"; +# Primary stuff +primary { + string = "primary string value"; + integer = 500; + float = 80.80; + negative = -50; + boolean = true; + not_true = FALSE; + nothing = NULL; + # Primary-sub stuff + sub { + key = "primary sub key value"; + } +} + +secondary { + another = "secondary another value"; + global_reference = global; + primary_sub_key = primary.sub.key; + another_again = .another; # References secondary.another + _under = 50; +} diff --git a/benchmark_test.go b/benchmark_test.go new file mode 100644 index 0000000..5320b91 --- /dev/null +++ b/benchmark_test.go @@ -0,0 +1,75 @@ +package forge_test + +import ( + "bytes" + "testing" + + "github.com/brettlangdon/forge" +) + +var exampleConfigBytes = []byte(` +# Global stuff +global = "global value"; +# Primary stuff +primary { + string = "primary string value"; + integer = 500; + float = 80.80; + negative = -50; + boolean = true; + not_true = FALSE; + nothing = NULL; + # Primary-sub stuff + sub { + key = "primary sub key value"; + } +} + +secondary { + another = "secondary another value"; + global_reference = global; + primary_sub_key = primary.sub.key; + another_again = .another; # References secondary.another + _under = 50; +} +`) + +var exampleConfigString = string(exampleConfigBytes) +var exampleConfigReader = bytes.NewBuffer(exampleConfigBytes) + +func BenchmarkParseBytes(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := forge.ParseBytes(exampleConfigBytes) + if err != nil { + panic(err) + } + } +} + +func BenchmarkParseString(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := forge.ParseString(exampleConfigString) + if err != nil { + panic(err) + } + } +} + +func BenchmarkParseReader(b *testing.B) { + for i := 0; i < b.N; i++ { + exampleConfigReader.Reset() + _, err := forge.ParseReader(exampleConfigReader) + if err != nil { + panic(err) + } + } +} + +func BenchmarkParseFile(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := forge.ParseFile("./benchmark.cfg") + if err != nil { + panic(err) + } + } +}