-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
51 lines (34 loc) · 976 Bytes
/
main_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
package main
import (
"fmt"
"strings"
"math"
"testing"
"io/ioutil"
"github.com/CapralDavid/Architecture4/engine"
)
func UpdateFileToDefault() {
ioutil.WriteFile("./testFile.txt", []byte("reverse kurwa"), 0644)
}
func ConcatStringNtimes(k int) {
for i := 0; i < k; i++ {
input,_ := ioutil.ReadFile("./testFile.txt")
parts := strings.Fields(string(input))
replacedString := fmt.Sprintf("%s%s", parts[1], parts[1])
newCmd := fmt.Sprintf("%s %s", parts[0], replacedString)
ioutil.WriteFile("./testFile.txt", []byte(newCmd), 0644)
}
}
func BenchmarkParser(b *testing.B) {
for i := 0; i < 12; i++ {
UpdateFileToDefault()
ConcatStringNtimes(i)
cmd, _ := ioutil.ReadFile("./testFile.txt")
b.Run(fmt.Sprintf("len=%d", int(math.Pow(2.0, float64(i)))), func(b *testing.B) {
for i := 0; i < b.N; i++ {
engine.Parse(string(cmd))
}
})
UpdateFileToDefault()
}
}