|
| 1 | +package types |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/dolthub/go-mysql-server/sql" |
| 5 | + "github.com/dolthub/vitess/go/sqltypes" |
| 6 | + "github.com/shopspring/decimal" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +var result_ sqltypes.Value |
| 11 | + |
| 12 | +func BenchmarkNumI64SQL(b *testing.B) { |
| 13 | + var res sqltypes.Value |
| 14 | + t := Int64 |
| 15 | + ctx := sql.NewEmptyContext() |
| 16 | + for i := 0; i < b.N; i++ { |
| 17 | + res, _ = t.SQL(ctx, nil, i) |
| 18 | + } |
| 19 | + result_ = res |
| 20 | +} |
| 21 | + |
| 22 | +func BenchmarkVarchar10SQL(b *testing.B) { |
| 23 | + var res sqltypes.Value |
| 24 | + t := MustCreateStringWithDefaults(sqltypes.VarChar, 10) |
| 25 | + ctx := sql.NewEmptyContext() |
| 26 | + for i := 0; i < b.N; i++ { |
| 27 | + res, _ = t.SQL(ctx, nil, "char") |
| 28 | + } |
| 29 | + result_ = res |
| 30 | +} |
| 31 | + |
| 32 | +func BenchmarkTimespanSQL(b *testing.B) { |
| 33 | + var res sqltypes.Value |
| 34 | + t := TimespanType_{} |
| 35 | + ctx := sql.NewEmptyContext() |
| 36 | + for i := 0; i < b.N; i++ { |
| 37 | + res, _ = t.SQL(ctx, nil, i%60) |
| 38 | + } |
| 39 | + result_ = res |
| 40 | +} |
| 41 | + |
| 42 | +func BenchmarkTimestampSQL(b *testing.B) { |
| 43 | + var res sqltypes.Value |
| 44 | + t := Timestamp |
| 45 | + ctx := sql.NewEmptyContext() |
| 46 | + for i := 0; i < b.N; i++ { |
| 47 | + res, _ = t.SQL(ctx, nil, "2019-12-31T12:00:00Z") |
| 48 | + } |
| 49 | + result_ = res |
| 50 | +} |
| 51 | + |
| 52 | +func BenchmarkDatetimeSQL(b *testing.B) { |
| 53 | + var res sqltypes.Value |
| 54 | + t := Datetime |
| 55 | + ctx := sql.NewEmptyContext() |
| 56 | + for i := 0; i < b.N; i++ { |
| 57 | + res, _ = t.SQL(ctx, nil, "2019-12-31T12:00:00Z") |
| 58 | + } |
| 59 | + result_ = res |
| 60 | +} |
| 61 | + |
| 62 | +func BenchmarkEnumSQL(b *testing.B) { |
| 63 | + var res sqltypes.Value |
| 64 | + t, _ := CreateEnumType([]string{"a", "b", "c"}, sql.Collation_Default) |
| 65 | + ctx := sql.NewEmptyContext() |
| 66 | + for i := 0; i < b.N; i++ { |
| 67 | + res, _ = t.SQL(ctx, nil, "a") |
| 68 | + } |
| 69 | + result_ = res |
| 70 | +} |
| 71 | + |
| 72 | +func BenchmarkSetSQL(b *testing.B) { |
| 73 | + var res sqltypes.Value |
| 74 | + t, _ := CreateSetType([]string{"a", "b", "c"}, sql.Collation_Default) |
| 75 | + ctx := sql.NewEmptyContext() |
| 76 | + for i := 0; i < b.N; i++ { |
| 77 | + res, _ = t.SQL(ctx, nil, "a") |
| 78 | + } |
| 79 | + result_ = res |
| 80 | +} |
| 81 | + |
| 82 | +func BenchmarkBitSQL(b *testing.B) { |
| 83 | + var res sqltypes.Value |
| 84 | + t := BitType_{numOfBits: 8} |
| 85 | + ctx := sql.NewEmptyContext() |
| 86 | + for i := 0; i < b.N; i++ { |
| 87 | + res, _ = t.SQL(ctx, nil, i%8) |
| 88 | + } |
| 89 | + result_ = res |
| 90 | +} |
| 91 | + |
| 92 | +func BenchmarkDecimalSQL(b *testing.B) { |
| 93 | + var res sqltypes.Value |
| 94 | + t, _ := CreateColumnDecimalType(2, 2) |
| 95 | + ctx := sql.NewEmptyContext() |
| 96 | + for i := 0; i < b.N; i++ { |
| 97 | + res, _ = t.SQL(ctx, nil, decimal.New(int64(i), 2)) |
| 98 | + } |
| 99 | + result_ = res |
| 100 | +} |
| 101 | + |
| 102 | +func BenchmarkNumF64SQL(b *testing.B) { |
| 103 | + var res sqltypes.Value |
| 104 | + t := Float64 |
| 105 | + ctx := sql.NewEmptyContext() |
| 106 | + for i := 0; i < b.N; i++ { |
| 107 | + res, _ = t.SQL(ctx, nil, i) |
| 108 | + } |
| 109 | + result_ = res |
| 110 | +} |
0 commit comments