forked from dre1080/go-orm-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (61 loc) · 1.53 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"flag"
"fmt"
"math/rand"
"runtime"
"strings"
"time"
"github.com/dre1080/go-orm-benchmark/benchs"
_ "github.com/lib/pq"
)
type ListOpts []string
func (opts *ListOpts) String() string {
return fmt.Sprint(*opts)
}
func (opts *ListOpts) Set(value string) error {
if value == "all" || strings.Index(" "+strings.Join(benchs.BrandNames, " ")+" ", " "+value+" ") != -1 {
} else {
return fmt.Errorf("wrong run name %s", value)
}
*opts = append(*opts, value)
return nil
}
func (opts ListOpts) Shuffle() {
rd := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < len(opts); i++ {
a := rd.Intn(len(opts))
b := rd.Intn(len(opts))
opts[a], opts[b] = opts[b], opts[a]
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var orms ListOpts
flag.IntVar(&benchs.ORM_MAX_IDLE, "max_idle", 200, "max idle conns")
flag.IntVar(&benchs.ORM_MAX_CONN, "max_conn", 200, "max open conns")
flag.StringVar(&benchs.ORM_SOURCE, "source", "postgres://pg:pg@localhost:5432/test?sslmode=disable", "postgres url source")
flag.IntVar(&benchs.ORM_MULTI, "multi", 1, "base query nums x multi")
flag.Var(&orms, "orm", "orm name: all, "+strings.Join(benchs.BrandNames, ", "))
flag.Parse()
var all bool
if len(orms) == 0 {
all = true
} else {
for _, n := range orms {
if n == "all" {
all = true
}
}
}
if all {
orms = ListOpts(benchs.BrandNames)
}
orms.Shuffle()
for _, n := range orms {
fmt.Println(n)
benchs.RunBenchmark(n)
}
fmt.Println("\nReports: \n")
fmt.Print(benchs.MakeReport())
}