Browse Source

add benchmarks

pull/16/head
Brett Langdon 11 years ago
parent
commit
8ac978881a
2 changed files with 99 additions and 0 deletions
  1. +24
    -0
      benchmark.cfg
  2. +75
    -0
      benchmark_test.go

+ 24
- 0
benchmark.cfg View File

@ -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;
}

+ 75
- 0
benchmark_test.go View File

@ -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)
}
}
}

Loading…
Cancel
Save