-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
37 lines (33 loc) · 986 Bytes
/
benchmark_test.go
File metadata and controls
37 lines (33 loc) · 986 Bytes
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
package main
import (
"fmt"
"testing"
"strings"
"math"
"io/ioutil"
"github.com/UniversityTeam/SoftwareEngineeringLab4/engine"
)
func AddNewStringToChange(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 %s", parts[0], replacedString, parts[2])
ioutil.WriteFile("./testFile.txt", []byte(newCmd), 0644)
}
}
func InitNewFile() {
ioutil.WriteFile("./testFile.txt", []byte("delete abcdefg a"), 0644)
}
func BenchmarkParse(b *testing.B) {
for i := 1; i <= 20; i++ {
InitNewFile()
AddNewStringToChange(i)
cmd, _ := ioutil.ReadFile("./testFile.txt")
b.Run(fmt.Sprintf("%d-length", int(math.Pow(2.0, float64(i)))), func(b *testing.B) {
for i := 0; i < b.N; i++ {
engine.Parse(string(cmd))
}
})
}
}