/
main.go
106 lines (85 loc) · 2.29 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"flag"
"log"
"os"
"runtime/pprof"
"time"
"github.com/araddon/qlbridge/datasource"
"github.com/araddon/qlbridge/expr"
"github.com/araddon/qlbridge/expr/builtins"
"github.com/araddon/qlbridge/rel"
"github.com/araddon/qlbridge/value"
"github.com/araddon/qlbridge/vm"
)
/*
go build && time ./_bm --command=parse --cpuprofile=cpu.prof
go tool pprof _bm cpu.prof
go build && time ./_bm --command=vm --cpuprofile=cpu.prof
go tool pprof _bm cpu.prof
*/
var (
cpuProfileFile string
memProfileFile string
logging = "info"
command = "parse"
msg = datasource.NewContextSimpleTs(
map[string]value.Value{
"int5": value.NewIntValue(5),
"item_count": value.NewStringValue("5"),
"reg_date": value.NewStringValue("2014/11/01"),
"user_id": value.NewStringValue("abc")},
time.Now(),
)
)
func init() {
flag.StringVar(&logging, "logging", "info", "logging [ debug,info ]")
flag.StringVar(&cpuProfileFile, "cpuprofile", "", "cpuprofile")
flag.StringVar(&memProfileFile, "memprofile", "", "memProfileFile")
flag.StringVar(&command, "command", "parse", "command to run [parse,vm]")
flag.Parse()
builtins.LoadAllBuiltins()
}
func main() {
if cpuProfileFile != "" {
f, err := os.Create(cpuProfileFile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
switch command {
case "parse":
runParse(100000, `select user_id, item_count * 2 as itemsx2, yy(reg_date) > 10 as regyy FROM stdio`, msg)
case "vm":
runVm(100000, `select user_id, item_count * 2 as itemsx2, yy(reg_date) > 10 as regyy FROM stdio`, msg)
}
}
func runParse(repeat int, sql string, readContext expr.ContextReader) {
for i := 0; i < repeat; i++ {
sel, err := rel.ParseSqlSelect(sql)
if err != nil {
panic(err.Error())
}
writeContext := datasource.NewContextSimple()
_, err = vm.EvalSql(sel, writeContext, readContext)
if err != nil {
panic(err.Error())
}
}
}
func runVm(repeat int, sql string, readContext expr.ContextReader) {
sel, err := rel.ParseSqlSelect(sql)
if err != nil {
panic(err.Error())
}
for i := 0; i < repeat; i++ {
writeContext := datasource.NewContextSimple()
_, err = vm.EvalSql(sel, writeContext, readContext)
//log.Println(writeContext.All())
if err != nil {
panic(err.Error())
}
}
}