-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark_test.go
66 lines (59 loc) · 1.35 KB
/
benchmark_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
59
60
61
62
63
64
65
66
package gojsx
import "testing"
// 优化前
// noCache 1,919,804 ns/op
// 优化 编译缓存
// 354,871 ns/op
func BenchmarkName(b *testing.B) {
j, err := NewJsx(Option{})
//j.debug = true
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
j.RegisterModule("@bysir/hollow", map[string]interface{}{
"getConfig": func() interface{} {
return map[string]interface{}{}
},
"getContents": func() interface{} {
return map[string]interface{}{
"list": []interface{}{},
}
},
})
b.Logf("-----begin-----")
for i := 0; i < b.N; i++ {
_, err := j.Exec("./test/Index", WithCache(false), WithAutoExecJsx(map[string]interface{}{}))
if err != nil {
b.Fatal(err)
}
}
}
func TestOne(t *testing.T) {
j, err := NewJsx(Option{})
j.debug = true
if err != nil {
t.Fatal(err)
}
j.RegisterModule("@bysir/hollow", map[string]interface{}{
"getConfig": func() interface{} {
return map[string]interface{}{}
},
"getContents": func() interface{} {
return map[string]interface{}{
"list": []interface{}{},
}
},
})
t.Logf("----- begin -----")
_, err = j.Exec("./test/Index", WithCache(false))
if err != nil {
t.Fatal(err)
}
t.Logf("----- second time -----")
e, err := j.Exec("./test/Index", WithCache(false), WithAutoExecJsx(map[string]interface{}{}))
if err != nil {
t.Fatal(err)
}
t.Logf("%+v", e.Default.(VDom))
}