good morning!!!!

Skip to content
Snippets Groups Projects
Commit 863ada14 authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Moving benchmarks to more appropriate places.

parent 426b3e7b
Branches
Tags
No related merge requests found
...@@ -4,72 +4,6 @@ import ( ...@@ -4,72 +4,6 @@ import (
"testing" "testing"
) )
func BenchmarkColumn(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Column{Name: "a"}
}
}
func BenchmarkCompileColumnNoCache(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = (&Column{Name: "a"}).Compile(defaultTemplate)
}
}
/*
func BenchmarkValues(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Values{{"a"}, {"b"}, {"c"}, {1}, {2}, {3}}
}
}
func BenchmarkCompileValues(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Values{{"a"}, {"b"}, {"c"}, {1}, {2}, {3}}.Compile(defaultTemplate)
}
}
func BenchmarkValueRaw(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = NewValue(Raw{Value: "a"}}
}
}
*/
func BenchmarkColumnValue(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: NewValue(Raw{Value: "7"})}
}
}
func BenchmarkCompileColumnValue(b *testing.B) {
cv := ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: NewValue(Raw{Value: "7"})}
for i := 0; i < b.N; i++ {
cv.Compile(defaultTemplate)
}
}
func BenchmarkColumnValues(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = NewColumnValues(
ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: NewValue(Raw{Value: "7"})},
)
}
}
func BenchmarkCompileColumnValues(b *testing.B) {
cv := NewColumnValues(ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: NewValue(Raw{Value: "7"})})
for i := 0; i < b.N; i++ {
cv.Compile(defaultTemplate)
}
}
func BenchmarkTable(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = NewTable("foo")
}
}
func BenchmarkCompileSelect(b *testing.B) { func BenchmarkCompileSelect(b *testing.B) {
var stmt Statement var stmt Statement
......
...@@ -15,6 +15,10 @@ type Column struct { ...@@ -15,6 +15,10 @@ type Column struct {
hash string hash string
} }
func NewColumn(name string) *Column {
return &Column{Name: name}
}
func (c *Column) Hash() string { func (c *Column) Hash() string {
if c.hash == "" { if c.hash == "" {
var s string var s string
......
...@@ -70,6 +70,12 @@ func TestColumnRaw(t *testing.T) { ...@@ -70,6 +70,12 @@ func TestColumnRaw(t *testing.T) {
} }
} }
func BenchmarkNewColumn(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = NewColumn("a")
}
}
func BenchmarkColumnHash(b *testing.B) { func BenchmarkColumnHash(b *testing.B) {
c := Column{Name: "name"} c := Column{Name: "name"}
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
...@@ -84,6 +90,13 @@ func BenchmarkColumnCompile(b *testing.B) { ...@@ -84,6 +90,13 @@ func BenchmarkColumnCompile(b *testing.B) {
} }
} }
func BenchmarkColumnCompileNoCache(b *testing.B) {
for i := 0; i < b.N; i++ {
c := Column{Name: "name"}
c.Compile(defaultTemplate)
}
}
func BenchmarkColumnWithDotCompile(b *testing.B) { func BenchmarkColumnWithDotCompile(b *testing.B) {
c := Column{Name: "role.name"} c := Column{Name: "role.name"}
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
......
...@@ -77,6 +77,12 @@ func TestColumnValues(t *testing.T) { ...@@ -77,6 +77,12 @@ func TestColumnValues(t *testing.T) {
} }
} }
func BenchmarkNewColumnValue(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: NewValue(Raw{Value: "7"})}
}
}
func BenchmarkColumnValueHash(b *testing.B) { func BenchmarkColumnValueHash(b *testing.B) {
cv := ColumnValue{Column: Column{Name: "id"}, Operator: "=", Value: NewValue(1)} cv := ColumnValue{Column: Column{Name: "id"}, Operator: "=", Value: NewValue(1)}
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
...@@ -91,6 +97,25 @@ func BenchmarkColumnValueCompile(b *testing.B) { ...@@ -91,6 +97,25 @@ func BenchmarkColumnValueCompile(b *testing.B) {
} }
} }
func BenchmarkColumnValueCompileNoCache(b *testing.B) {
for i := 0; i < b.N; i++ {
cv := ColumnValue{Column: Column{Name: "id"}, Operator: "=", Value: NewValue(1)}
cv.Compile(defaultTemplate)
}
}
func BenchmarkNewColumnValues(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = NewColumnValues(
ColumnValue{Column: Column{Name: "id"}, Operator: ">", Value: NewValue(8)},
ColumnValue{Column: Column{Name: "other.id"}, Operator: "<", Value: NewValue(Raw{Value: "100"})},
ColumnValue{Column: Column{Name: "name"}, Operator: "=", Value: NewValue("Haruki Murakami")},
ColumnValue{Column: Column{Name: "created"}, Operator: ">=", Value: NewValue(Raw{Value: "NOW()"})},
ColumnValue{Column: Column{Name: "modified"}, Operator: "<=", Value: NewValue(Raw{Value: "NOW()"})},
)
}
}
func BenchmarkColumnValuesHash(b *testing.B) { func BenchmarkColumnValuesHash(b *testing.B) {
cvs := NewColumnValues( cvs := NewColumnValues(
ColumnValue{Column: Column{Name: "id"}, Operator: ">", Value: NewValue(8)}, ColumnValue{Column: Column{Name: "id"}, Operator: ">", Value: NewValue(8)},
...@@ -116,3 +141,16 @@ func BenchmarkColumnValuesCompile(b *testing.B) { ...@@ -116,3 +141,16 @@ func BenchmarkColumnValuesCompile(b *testing.B) {
cvs.Compile(defaultTemplate) cvs.Compile(defaultTemplate)
} }
} }
func BenchmarkColumnValuesCompileNoCache(b *testing.B) {
for i := 0; i < b.N; i++ {
cvs := NewColumnValues(
ColumnValue{Column: Column{Name: "id"}, Operator: ">", Value: NewValue(8)},
ColumnValue{Column: Column{Name: "other.id"}, Operator: "<", Value: NewValue(Raw{Value: "100"})},
ColumnValue{Column: Column{Name: "name"}, Operator: "=", Value: NewValue("Haruki Murakami")},
ColumnValue{Column: Column{Name: "created"}, Operator: ">=", Value: NewValue(Raw{Value: "NOW()"})},
ColumnValue{Column: Column{Name: "modified"}, Operator: "<=", Value: NewValue(Raw{Value: "NOW()"})},
)
cvs.Compile(defaultTemplate)
}
}
...@@ -108,6 +108,12 @@ func TestTableEmpty(t *testing.T) { ...@@ -108,6 +108,12 @@ func TestTableEmpty(t *testing.T) {
} }
} }
func BenchmarkNewTable(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = NewTable("foo")
}
}
func BenchmarkTableHash(b *testing.B) { func BenchmarkTableHash(b *testing.B) {
t := NewTable("name") t := NewTable("name")
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment