-
Notifications
You must be signed in to change notification settings - Fork 12
/
y_bench.go
93 lines (75 loc) · 2.16 KB
/
y_bench.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
package main
import (
"fmt"
"math/rand"
"time"
)
// *****************************************************************************
// ************************** Analysis Benchmark *******************************
func benchHash(seedPts seedList) (hashes []uint64) {
hashes = make([]uint64, len(seedPts))
start := time.Now()
for i, seedPt := range seedPts {
hashes[i] = hashTrBits(seedPt.traceBits)
}
fmt.Printf("Avg time per hash computation: %v.\n",
time.Now().Sub(start)/time.Duration(len(seedPts)))
return hashes
}
// *****************************************************************************
// *************************** Mutation Benchmark ******************************
var benchMutDict [][]byte
func benchMutSeed(seed *seedT) (durs map[string]time.Duration, ret [][]byte) {
durs = make(map[string]time.Duration)
rSrc := rand.New(rand.NewSource(rand.Int63()))
m := makeBasicMutator(rSrc, benchMutDict, nil, 1, len(seed.input))
for fi, f := range m.funcs {
tcLen := len(seed.input)
tc := make([]byte, tcLen)
copy(tc, seed.input)
oldTc := tc
contracts := make([]mutationContract, len(m.funcs))
for i, f := range m.funcs {
contracts[i] = f.getMutContract(tcLen)
}
name := f.name()
contract := contracts[fi]
var benchNb int = 1e7
if contract.changeLen != nil {
benchNb /= 100
}
start := time.Now()
for i := 0; i < benchNb; i++ {
specs := contract.specs
decisions := make([]int, len(specs))
for j, specs := range specs {
var dec int
if specs.dependency != nil {
dec = specs.dependency(m.rSrc, decisions)
} else {
interval := specs.max - specs.min
dec = specs.min
if interval > 1 {
dec += m.rSrc.Intn(interval)
}
}
decisions[j] = dec
}
tc = f.mutate(decisions, tc)
if len(tc) != len(oldTc) {
tc = oldTc
}
if contract.changeLen != nil {
tcLen = contract.changeLen(decisions, tcLen)
for i, f := range m.funcs {
contracts[i] = f.getMutContract(tcLen)
}
}
}
dur := time.Now().Sub(start) / time.Duration(benchNb)
fmt.Printf("Avg mutation time of %s: %v. \n", name, dur)
durs[name] = dur
ret = append(ret, tc)
}
return durs, ret
}