Skip to content

Commit 6fb715e

Browse files
committed
added line-level benchmark
1 parent 8b58f93 commit 6fb715e

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

diffmatchpatch/dmp_test.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,23 +1364,36 @@ func Benchmark_DiffCommonSuffix(b *testing.B) {
13641364
}
13651365

13661366
func Benchmark_DiffMainLarge(b *testing.B) {
1367-
bytes1, err := ioutil.ReadFile("speedtest1.txt")
1368-
if err != nil {
1369-
b.Fatal(err)
1370-
}
1371-
bytes2, err := ioutil.ReadFile("speedtest2.txt")
1372-
if err != nil {
1373-
b.Fatal(err)
1374-
}
1375-
s1 := string(bytes1)
1376-
s2 := string(bytes2)
1367+
s1 := readFile("speedtest1.txt", b)
1368+
s2 := readFile("speedtest2.txt", b)
13771369
dmp := New()
13781370
b.ResetTimer()
13791371
for i := 0; i < b.N; i++ {
13801372
dmp.DiffMain(s1, s2, true)
13811373
}
13821374
}
13831375

1376+
func Benchmark_DiffMainLargeLines(b *testing.B) {
1377+
s1 := readFile("speedtest1.txt", b)
1378+
s2 := readFile("speedtest2.txt", b)
1379+
dmp := New()
1380+
b.ResetTimer()
1381+
for i := 0; i < b.N; i++ {
1382+
text1, text2, linearray := dmp.DiffLinesToChars(s1, s2)
1383+
diffs := dmp.DiffMain(text1, text2, false)
1384+
diffs = dmp.DiffCharsToLines(diffs, linearray)
1385+
}
1386+
}
1387+
1388+
func readFile(filename string, b *testing.B) string {
1389+
bytes, err := ioutil.ReadFile(filename)
1390+
if err != nil {
1391+
b.Fatal(err)
1392+
}
1393+
return string(bytes)
1394+
}
1395+
1396+
13841397

13851398

13861399

0 commit comments

Comments
 (0)