-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain_test.go
47 lines (42 loc) · 1.03 KB
/
main_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
package main
import (
"database/sql"
"os"
"testing"
)
func TestCompact(t *testing.T) {
c := compact{
lineNumbers: []int{10, 13, 15},
fileID: 1,
}
if c.String() != "1 @n 10,3,2" {
t.Error(c.String())
}
c = compact{
lineNumbers: []int{10, 11, 12, 13, 15, 16},
fileID: 1,
}
if c.String() != "1 @n 10-3,2-1" {
t.Error(c.String())
}
}
func BenchmarkInsert(b *testing.B) {
file := gtags
_ = os.Remove("./" + file.String())
g, _ := sql.Open("sqlite3", file.String())
_, _ = g.Exec(`create table db (key text, dat text, extra text)`)
for i := 0; i < b.N; i++ {
_, _ = g.Exec(`insert into db (key, dat, extra) values (?, ?, ?)`, "key", "dat", "extra")
}
}
func BenchmarkInsertCommit(b *testing.B) {
file := gtags
_ = os.Remove("./" + file.String())
g, _ := sql.Open("sqlite3", file.String())
_, _ = g.Exec(`create table db (key text, dat text, extra text)`)
t, _ := g.Begin()
for i := 0; i < b.N; i++ {
_, _ = t.Exec(`insert into db (key, dat, extra) values (?, ?, ?)`, "key", "dat", "extra")
}
_ = t.Commit()
}