testing: benchmarks moved to separate files
This commit is contained in:
22
mapper_bench_test.go
Normal file
22
mapper_bench_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gocqlx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkSnakeCase(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
snakeCase(snakeTable[b.N%len(snakeTable)].N)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkToLower(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
strings.ToLower(snakeTable[b.N%len(snakeTable)].N)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,9 @@
|
|||||||
// Use of this source code is governed by a ALv2-style
|
// Use of this source code is governed by a ALv2-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build !integration
|
|
||||||
|
|
||||||
package gocqlx
|
package gocqlx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -72,15 +69,3 @@ func TestSnakeCase(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSnakeCase(b *testing.B) {
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
snakeCase(snakeTable[b.N%len(snakeTable)].N)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkToLower(b *testing.B) {
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
strings.ToLower(snakeTable[b.N%len(snakeTable)].N)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
14
qb/batch_bench_test.go
Normal file
14
qb/batch_bench_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package qb
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func BenchmarkBatchBuilder(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Batch().Add(mockBuilder{"INSERT INTO cycling.cyclist_name (id,user_uuid,firstname) VALUES (?,?,?) ", []string{"id", "user_uuid", "firstname"}}).ToCql()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,10 +75,3 @@ func TestBatchBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBatchBuilder(b *testing.B) {
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Batch().Add(mockBuilder{"INSERT INTO cycling.cyclist_name (id,user_uuid,firstname) VALUES (?,?,?) ", []string{"id", "user_uuid", "firstname"}}).ToCql()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
25
qb/cmp_bench_test.go
Normal file
25
qb/cmp_bench_test.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package qb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkCmp(b *testing.B) {
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buf.Reset()
|
||||||
|
c := cmps{
|
||||||
|
Eq("id"),
|
||||||
|
Lt("user_uuid"),
|
||||||
|
LtOrEq("firstname"),
|
||||||
|
Gt("stars"),
|
||||||
|
}
|
||||||
|
c.writeCql(&buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -155,18 +155,3 @@ func TestCmp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCmp(b *testing.B) {
|
|
||||||
buf := bytes.Buffer{}
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
buf.Reset()
|
|
||||||
c := cmps{
|
|
||||||
Eq("id"),
|
|
||||||
Lt("user_uuid"),
|
|
||||||
LtOrEq("firstname"),
|
|
||||||
Gt("stars"),
|
|
||||||
}
|
|
||||||
c.writeCql(&buf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
14
qb/delete_bench_test.go
Normal file
14
qb/delete_bench_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package qb
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func BenchmarkDeleteBuilder(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Delete("cycling.cyclist_name").Columns("id", "user_uuid", "firstname", "stars").Where(Eq("id")).ToCql()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,10 +72,3 @@ func TestDeleteBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDeleteBuilder(b *testing.B) {
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Delete("cycling.cyclist_name").Columns("id", "user_uuid", "firstname", "stars").Where(Eq("id")).ToCql()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
14
qb/insert_bench_test.go
Normal file
14
qb/insert_bench_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package qb
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func BenchmarkInsertBuilder(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Insert("cycling.cyclist_name").Columns("id", "user_uuid", "firstname", "stars").ToCql()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -77,10 +77,3 @@ func TestInsertBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInsertBuilder(b *testing.B) {
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Insert("cycling.cyclist_name").Columns("id", "user_uuid", "firstname", "stars").ToCql()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
14
qb/select_bench_test.go
Normal file
14
qb/select_bench_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package qb
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func BenchmarkSelectBuilder(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Select("cycling.cyclist_name").Columns("id", "user_uuid", "firstname", "stars").Where(Eq("id")).ToCql()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -106,10 +106,3 @@ func TestSelectBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSelectBuilder(b *testing.B) {
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Select("cycling.cyclist_name").Columns("id", "user_uuid", "firstname", "stars").Where(Eq("id")).ToCql()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
14
qb/update_bench_test.go
Normal file
14
qb/update_bench_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package qb
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func BenchmarkUpdateBuilder(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Update("cycling.cyclist_name").Set("id", "user_uuid", "firstname", "stars").Where(Eq("id")).ToCql()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -126,10 +126,3 @@ func TestUpdateBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUpdateBuilder(b *testing.B) {
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Update("cycling.cyclist_name").Set("id", "user_uuid", "firstname", "stars").Where(Eq("id")).ToCql()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
52
queryx_bench_test.go
Normal file
52
queryx_bench_test.go
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (C) 2017 ScyllaDB
|
||||||
|
// Use of this source code is governed by a ALv2-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gocqlx_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gocql/gocql"
|
||||||
|
"github.com/scylladb/gocqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkCompileNamedQuery(b *testing.B) {
|
||||||
|
q := []byte("INSERT INTO cycling.cyclist_name (id, user_uuid, firstname, stars) VALUES (:id, :user_uuid, :firstname, :stars)")
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
gocqlx.CompileNamedQuery(q)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkBindStruct(b *testing.B) {
|
||||||
|
q := gocqlx.Query(&gocql.Query{}, []string{"name", "age", "first", "last"})
|
||||||
|
type t struct {
|
||||||
|
Name string
|
||||||
|
Age int
|
||||||
|
First string
|
||||||
|
Last string
|
||||||
|
}
|
||||||
|
am := t{"Jason Moiron", 30, "Jason", "Moiron"}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
q.BindStruct(am)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkBindMap(b *testing.B) {
|
||||||
|
q := gocqlx.Queryx{
|
||||||
|
Query: &gocql.Query{},
|
||||||
|
Names: []string{"name", "age", "first", "last"},
|
||||||
|
}
|
||||||
|
am := map[string]interface{}{
|
||||||
|
"name": "Jason Moiron",
|
||||||
|
"age": 30,
|
||||||
|
"first": "Jason",
|
||||||
|
"last": "Moiron",
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
q.BindMap(am)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,11 @@
|
|||||||
// Use of this source code is governed by a ALv2-style
|
// Use of this source code is governed by a ALv2-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build !integration
|
|
||||||
|
|
||||||
package gocqlx
|
package gocqlx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gocql/gocql"
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -64,14 +61,6 @@ func TestCompileQuery(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCompileNamedQuery(b *testing.B) {
|
|
||||||
q := []byte("INSERT INTO cycling.cyclist_name (id, user_uuid, firstname, stars) VALUES (:id, :user_uuid, :firstname, :stars)")
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
CompileNamedQuery(q)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBindStruct(t *testing.T) {
|
func TestBindStruct(t *testing.T) {
|
||||||
v := &struct {
|
v := &struct {
|
||||||
Name string
|
Name string
|
||||||
@@ -132,21 +121,6 @@ func TestBindStruct(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBindStruct(b *testing.B) {
|
|
||||||
q := Query(&gocql.Query{}, []string{"name", "age", "first", "last"})
|
|
||||||
type t struct {
|
|
||||||
Name string
|
|
||||||
Age int
|
|
||||||
First string
|
|
||||||
Last string
|
|
||||||
}
|
|
||||||
am := t{"Jason Moiron", 30, "Jason", "Moiron"}
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
q.BindStruct(am)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBindMap(t *testing.T) {
|
func TestBindMap(t *testing.T) {
|
||||||
v := map[string]interface{}{
|
v := map[string]interface{}{
|
||||||
"name": "name",
|
"name": "name",
|
||||||
@@ -175,20 +149,3 @@ func TestBindMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBindMap(b *testing.B) {
|
|
||||||
q := Queryx{
|
|
||||||
Query: &gocql.Query{},
|
|
||||||
Names: []string{"name", "age", "first", "last"},
|
|
||||||
}
|
|
||||||
am := map[string]interface{}{
|
|
||||||
"name": "Jason Moiron",
|
|
||||||
"age": 30,
|
|
||||||
"first": "Jason",
|
|
||||||
"last": "Moiron",
|
|
||||||
}
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
q.BindMap(am)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user