1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-25 22:01:39 +02:00

Added some benchmarks (#139)

This commit is contained in:
Tim Voronov
2018-10-24 19:40:57 -04:00
committed by GitHub
parent ebea64da37
commit 19dbf12296
18 changed files with 932 additions and 230 deletions

View File

@@ -12,14 +12,14 @@ func TestLogicalOperators(t *testing.T) {
Convey("Should compile RETURN 2 > 1 AND 1 > 0", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN 2 > 1 AND 1 > 0
`)
So(err, ShouldBeNil)
So(prog, ShouldHaveSameTypeAs, &runtime.Program{})
So(p, ShouldHaveSameTypeAs, &runtime.Program{})
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, "true")
@@ -28,14 +28,14 @@ func TestLogicalOperators(t *testing.T) {
Convey("Should compile RETURN 2 > 1 OR 1 < 0", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN 2 > 1 OR 1 < 0
`)
So(err, ShouldBeNil)
So(prog, ShouldHaveSameTypeAs, &runtime.Program{})
So(p, ShouldHaveSameTypeAs, &runtime.Program{})
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, "true")
@@ -44,13 +44,13 @@ func TestLogicalOperators(t *testing.T) {
Convey("1 || 7 should return 1", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN 1 || 7
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, "1")
@@ -59,13 +59,13 @@ func TestLogicalOperators(t *testing.T) {
Convey("NONE || 'foo' should return 'foo'", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN NONE || 'foo'
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `"foo"`)
@@ -74,13 +74,13 @@ func TestLogicalOperators(t *testing.T) {
Convey("NONE && true should return null", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN NONE && true
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `null`)
@@ -89,13 +89,13 @@ func TestLogicalOperators(t *testing.T) {
Convey("'' && true should return ''", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN '' && true
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `""`)
@@ -104,13 +104,13 @@ func TestLogicalOperators(t *testing.T) {
Convey("true && 23 should return '23", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN true && 23
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `23`)
@@ -119,13 +119,13 @@ func TestLogicalOperators(t *testing.T) {
Convey("NOT TRUE should return false", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
RETURN NOT TRUE
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
@@ -134,7 +134,7 @@ func TestLogicalOperators(t *testing.T) {
Convey("NOT u.valid should return true", t, func() {
c := compiler.New()
prog, err := c.Compile(`
p, err := c.Compile(`
LET u = { valid: false }
RETURN NOT u.valid
@@ -142,9 +142,29 @@ func TestLogicalOperators(t *testing.T) {
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
out, err := p.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
}
func BenchmarkLogicalOperatorsAnd(b *testing.B) {
p := compiler.New().MustCompile(`
RETURN 2 > 1 AND 1 > 0
`)
for n := 0; n < b.N; n++ {
p.Run(context.Background())
}
}
func BenchmarkLogicalOperatorsOr(b *testing.B) {
p := compiler.New().MustCompile(`
RETURN 2 > 1 OR 1 < 0
`)
for n := 0; n < b.N; n++ {
p.Run(context.Background())
}
}