forked from timtadh/regex-machines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.go
64 lines (60 loc) · 1.53 KB
/
time.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
package main
import "fmt"
import timelib "time"
import "math"
import "github.com/timtadh/regex-machines/inst"
import . "github.com/timtadh/regex-machines/machines"
func test_case(n int) (inst.InstSlice, []byte) {
program := make(inst.InstSlice, n*3+1)
text := make([]byte, n)
i := uint32(0)
for j := 0; j < n; j++ {
program[i] = inst.New(inst.SPLIT, i+1, i+2)
program[i+1] = inst.New(inst.CHAR, 'a', 0)
i += 2
}
for j := 0; j < n; j++ {
text[j] = 'a'
program[i] = inst.New(inst.CHAR, 'a', 0)
i++
}
program[i] = inst.New(inst.MATCH, 0, 0)
return program, text
}
func time() float64 {
t := timelib.Now()
sec := t.Unix()
nsec := t.UnixNano()
return float64(sec) + float64(nsec)*math.Pow(10.0, -9)
}
func main() {
// fmt.Println("test, recursive, backtracking, thompson")
for i := 1; i <= 50; i++ {
program, text := test_case(i)
var t1, t2, t3 float64
if i <= 20 {
{
s := time()
Recursive(program, text)
e := time()
t1 = e - s
}
{
s := time()
Backtracking(program, text)
e := time()
t2 = e - s
}
} else {
t1 = 0.0
t2 = 0.0
}
{
s := time()
Thompson(program, text)
e := time()
t3 = e - s
}
fmt.Printf("%v, %f, %f, %f\n", i, t1, t2, t3)
}
}