-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperform_test.go
58 lines (47 loc) · 1.28 KB
/
perform_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package rmdb
import (
"bytes"
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"math/rand"
"testing"
)
var db *Database
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
func GetName() string {
var str bytes.Buffer
for i := 0; i < 10; i++ {
str.WriteByte(alphabet[rand.Int()%36])
}
return str.String()
}
func GetSql() string {
name, _ := EncodeData(GetName())
age, _ := EncodeData(int64(rand.Int()))
id, _ := EncodeData(int64(rand.Int()))
price, _ := EncodeData(rand.Float64())
sql := fmt.Sprint("insert into test (name, age, id, price) values (", string(name), ", ", string(age), ", ", string(id), ", ", string(price), ");")
return sql
}
func GetNumSql(num int) string {
nameStr, _ := json.Marshal(fmt.Sprint("iam", num))
ageStr, _ := json.Marshal(int64(num))
idStr, _ := json.Marshal(int64(num + 1))
priceStr, _ := json.Marshal(float64(num) * 0.01)
sql := fmt.Sprintf("insert into test (name, age, id, price) values (%s, %s, %s, %s);", string(nameStr), string(ageStr), string(idStr), string(priceStr))
return sql
}
func TestSql(t *testing.T) {
fmt.Println(GetNumSql(11451))
}
func BenchmarkInsert(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
sql := GetSql()
var err error
for i := 0; i < b.N; i++ {
err = db.Update(sql)
assert.Nil(b, err)
}
}