Skip to content

Commit

Permalink
eskip: add BenchmarkRouteString
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov committed Sep 5, 2023
1 parent 6a6ed84 commit bc6bc82
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions eskip/eskip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,3 +829,65 @@ func BenchmarkParsePredicates(b *testing.B) {
_, _ = ParsePredicates(doc)
}
}

var stringSink string

func BenchmarkRouteString(b *testing.B) {
doc := `
Method("GET") &&
Path("/foo") &&
Host(/foo/) &&
Host(/bar/) &&
Host(/baz/) &&
PathRegexp(/C/) &&
PathRegexp(/B/) &&
PathRegexp(/A/) &&
Header("Foo", "Bar") &&
Header("Bar", "Baz") &&
Header("Qux", "Bar") &&
HeaderRegexp("B", /3/) &&
HeaderRegexp("B", /2/) &&
HeaderRegexp("A", /1/) &&
Foo("bar", "baz") &&
True() -> <shunt>`

rr, err := Parse(doc)
if err != nil {
b.Fatal(err)
}
r := rr[0]
var s string

b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
s = r.String()
}
stringSink = s
}

func BenchmarkRouteStringNoRepeatedPredicates(b *testing.B) {
doc := `
Method("GET") &&
Path("/foo") &&
Host(/foo/) &&
PathRegexp(/A/) &&
Header("Foo", "Bar") &&
HeaderRegexp("A", /1/) &&
Foo("bar", "baz") &&
True() -> <shunt>`

rr, err := Parse(doc)
if err != nil {
b.Fatal(err)
}
r := rr[0]
var s string

b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
s = r.String()
}
stringSink = s
}

0 comments on commit bc6bc82

Please sign in to comment.