From a8febbc71ee359534fba2c2edcaf89c70a776b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Tue, 22 May 2018 16:37:02 +0200 Subject: [PATCH] testing: benchmarks moved to separate files --- integration_test.go => iterx_test.go | 0 mapper_bench_test.go | 22 ++++++++++++ mapper_test.go | 15 -------- qb/batch_bench_test.go | 14 ++++++++ qb/batch_test.go | 7 ---- qb/cmp_bench_test.go | 25 +++++++++++++ qb/cmp_test.go | 15 -------- qb/delete_bench_test.go | 14 ++++++++ qb/delete_test.go | 7 ---- qb/insert_bench_test.go | 14 ++++++++ qb/insert_test.go | 7 ---- qb/select_bench_test.go | 14 ++++++++ qb/select_test.go | 7 ---- qb/update_bench_test.go | 14 ++++++++ qb/update_test.go | 7 ---- queryx_bench_test.go | 52 ++++++++++++++++++++++++++++ queryx_test.go | 43 ----------------------- 17 files changed, 169 insertions(+), 108 deletions(-) rename integration_test.go => iterx_test.go (100%) create mode 100644 mapper_bench_test.go create mode 100644 qb/batch_bench_test.go create mode 100644 qb/cmp_bench_test.go create mode 100644 qb/delete_bench_test.go create mode 100644 qb/insert_bench_test.go create mode 100644 qb/select_bench_test.go create mode 100644 qb/update_bench_test.go create mode 100644 queryx_bench_test.go diff --git a/integration_test.go b/iterx_test.go similarity index 100% rename from integration_test.go rename to iterx_test.go diff --git a/mapper_bench_test.go b/mapper_bench_test.go new file mode 100644 index 0000000..26f07eb --- /dev/null +++ b/mapper_bench_test.go @@ -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) + } +} diff --git a/mapper_test.go b/mapper_test.go index 26601f6..2ec05db 100644 --- a/mapper_test.go +++ b/mapper_test.go @@ -2,12 +2,9 @@ // Use of this source code is governed by a ALv2-style // license that can be found in the LICENSE file. -// +build !integration - package gocqlx import ( - "strings" "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) - } -} diff --git a/qb/batch_bench_test.go b/qb/batch_bench_test.go new file mode 100644 index 0000000..7a07a92 --- /dev/null +++ b/qb/batch_bench_test.go @@ -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() + } +} diff --git a/qb/batch_test.go b/qb/batch_test.go index ca2d796..f902220 100644 --- a/qb/batch_test.go +++ b/qb/batch_test.go @@ -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() - } -} diff --git a/qb/cmp_bench_test.go b/qb/cmp_bench_test.go new file mode 100644 index 0000000..bb8abc4 --- /dev/null +++ b/qb/cmp_bench_test.go @@ -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) + } +} diff --git a/qb/cmp_test.go b/qb/cmp_test.go index a46ee23..ff4b08d 100644 --- a/qb/cmp_test.go +++ b/qb/cmp_test.go @@ -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) - } -} diff --git a/qb/delete_bench_test.go b/qb/delete_bench_test.go new file mode 100644 index 0000000..222c138 --- /dev/null +++ b/qb/delete_bench_test.go @@ -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() + } +} diff --git a/qb/delete_test.go b/qb/delete_test.go index 35ab96c..2388d77 100644 --- a/qb/delete_test.go +++ b/qb/delete_test.go @@ -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() - } -} diff --git a/qb/insert_bench_test.go b/qb/insert_bench_test.go new file mode 100644 index 0000000..51578b8 --- /dev/null +++ b/qb/insert_bench_test.go @@ -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() + } +} diff --git a/qb/insert_test.go b/qb/insert_test.go index b0cd24b..47f2134 100644 --- a/qb/insert_test.go +++ b/qb/insert_test.go @@ -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() - } -} diff --git a/qb/select_bench_test.go b/qb/select_bench_test.go new file mode 100644 index 0000000..7932529 --- /dev/null +++ b/qb/select_bench_test.go @@ -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() + } +} diff --git a/qb/select_test.go b/qb/select_test.go index 3423873..023f277 100644 --- a/qb/select_test.go +++ b/qb/select_test.go @@ -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() - } -} diff --git a/qb/update_bench_test.go b/qb/update_bench_test.go new file mode 100644 index 0000000..5d44447 --- /dev/null +++ b/qb/update_bench_test.go @@ -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() + } +} diff --git a/qb/update_test.go b/qb/update_test.go index 70eeaf6..21a55be 100644 --- a/qb/update_test.go +++ b/qb/update_test.go @@ -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() - } -} diff --git a/queryx_bench_test.go b/queryx_bench_test.go new file mode 100644 index 0000000..50e58b9 --- /dev/null +++ b/queryx_bench_test.go @@ -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) + } +} diff --git a/queryx_test.go b/queryx_test.go index d52f1f0..eece6bc 100644 --- a/queryx_test.go +++ b/queryx_test.go @@ -2,14 +2,11 @@ // Use of this source code is governed by a ALv2-style // license that can be found in the LICENSE file. -// +build !integration - package gocqlx import ( "testing" - "github.com/gocql/gocql" "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) { v := &struct { 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) { v := map[string]interface{}{ "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) - } -}