Skip to content

Commit

Permalink
Add benchmarks.
Browse files Browse the repository at this point in the history
Refs #586

goos: linux
goarch: amd64
pkg: github.com/sensu/sensu-go/types/dynamic
BenchmarkQueryGovaluateSimple-4    	  500000	      2069 ns/op	     992 B/op	      25 allocs/op
BenchmarkQueryGovaluateComplex-4   	  200000	      6212 ns/op	    2544 B/op	      75 allocs/op
BenchmarkUnmarshal-4               	  200000	      6492 ns/op	    6568 B/op	      57 allocs/op
BenchmarkMarshal-4                 	  300000	      4556 ns/op	    6512 B/op	      40 allocs/op
PASS
ok  	github.com/sensu/sensu-go/types/dynamic	6.172s
  • Loading branch information
echlebek committed Nov 23, 2017
1 parent 49f3182 commit 0f062ba
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions types/dynamic/dynamic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ func TestQueryGovaluateSimple(t *testing.T) {
require.Equal(t, true, result)
}

func BenchmarkQueryGovaluateSimple(b *testing.B) {
m := MyType{
extended: []byte(`{"hello":5}`),
}

expr, err := govaluate.NewEvaluableExpression("hello == 5")
require.Nil(b, err)
require.NotNil(b, expr)
b.ResetTimer()

for i := 0; i < b.N; i++ {
expr.Eval(m)
}
}

func TestQueryGovaluateComplex(t *testing.T) {
m := MyType{
extended: []byte(`{"hello":{"foo":5,"bar":6.0}}`),
Expand Down Expand Up @@ -268,6 +283,21 @@ func TestQueryGovaluateComplex(t *testing.T) {
require.Equal(t, true, result)
}

func BenchmarkQueryGovaluateComplex(b *testing.B) {
m := MyType{
extended: []byte(`{"hello":{"foo":5,"bar":6.0}}`),
}

expr, err := govaluate.NewEvaluableExpression("hello.Foo == 5")
require.Nil(b, err)
require.NotNil(b, expr)
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, _ = expr.Eval(m)
}
}

func TestMarshalUnmarshal(t *testing.T) {
data := []byte(`{"bar":null,"foo":"hello","a":10,"b":"c"}`)
var m MyType
Expand All @@ -278,3 +308,21 @@ func TestMarshalUnmarshal(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, data, b)
}

func BenchmarkUnmarshal(b *testing.B) {
data := []byte(`{"bar":null,"foo":"hello","a":10,"b":"c"}`)
var m MyType
for i := 0; i < b.N; i++ {
_ = json.Unmarshal(data, &m)
}
}

func BenchmarkMarshal(b *testing.B) {
data := []byte(`{"bar":null,"foo":"hello","a":10,"b":"c"}`)
var m MyType
json.Unmarshal(data, &m)
b.ResetTimer()
for i := 0; i < b.N; i++ {
json.Marshal(m)
}
}

0 comments on commit 0f062ba

Please sign in to comment.