good morning!!!!

Skip to content
Snippets Groups Projects
benchmark_test.go 2.88 KiB
Newer Older
package sqlgen

import (
	"testing"
)

José Carlos Nieto's avatar
José Carlos Nieto committed
func BenchmarkColumn(b *testing.B) {
	for i := 0; i < b.N; i++ {
func BenchmarkCompileColumnNoCache(b *testing.B) {
José Carlos Nieto's avatar
José Carlos Nieto committed
	for i := 0; i < b.N; i++ {
		_ = (&Column{Name: "a"}).Compile(defaultTemplate)
José Carlos Nieto's avatar
José Carlos Nieto committed
	}
}

func BenchmarkValue(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = Value{"a"}
	}
}

func BenchmarkCompileValueNoCache(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = Value{"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)
	}
}

José Carlos Nieto's avatar
José Carlos Nieto committed
func BenchmarkValueRaw(b *testing.B) {
	for i := 0; i < b.N; i++ {
José Carlos Nieto's avatar
José Carlos Nieto committed
	}
}

func BenchmarkColumnValue(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: Value{Raw{Value: "7"}}}
func BenchmarkCompileColumnValue(b *testing.B) {
	cv := ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: Value{Raw{Value: "7"}}}
	}
}

func BenchmarkColumnValues(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = NewColumnValues(
			ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: Value{Raw{Value: "7"}}},
		)
	}
}

func BenchmarkCompileColumnValues(b *testing.B) {
	cv := NewColumnValues(ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: Value{Raw{Value: "7"}}})
	}
}

func BenchmarkWhere(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = Where{
			&ColumnValue{Column: Column{Name: "baz"}, Operator: "=", Value: Value{99}},
		}
	}
}

func BenchmarkCompileWhere(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = Where{
			&ColumnValue{Column: Column{Name: "baz"}, Operator: "=", Value: Value{99}},
José Carlos Nieto's avatar
José Carlos Nieto committed
func BenchmarkTable(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = Table{"foo"}
	}
}

func BenchmarkCompileTable(b *testing.B) {
José Carlos Nieto's avatar
José Carlos Nieto committed
	for i := 0; i < b.N; i++ {
		t = Table{"foo"}.Compile(defaultTemplate)
		if t != `"foo"` {
			b.Fatal("Caching failed.")
		}
	}
}

func BenchmarkCompileRandomTable(b *testing.B) {
	var t string
	var m, n int
	var s, e string

	for i := 0; i < b.N; i++ {
		m, n = rand.Int(), rand.Int()
		s = fmt.Sprintf(`%s as %s`, m, n)
		e = fmt.Sprintf(`"%s" AS "%s"`, m, n)

		t = Table{s}.Compile(defaultTemplate)
		if t != e {
			b.Fatal()
		}
func BenchmarkCompileSelect(b *testing.B) {
	var stmt Statement

	for i := 0; i < b.N; i++ {
		stmt = Statement{
			Type:  SqlSelectCount,
			Table: Table{"table_name"},
			Where: Where{
				&ColumnValue{Column: Column{Name: "a"}, Operator: "=", Value: Value{Raw{Value: "7"}}},
José Carlos Nieto's avatar
José Carlos Nieto committed
		_ = stmt.Compile(defaultTemplate)