-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
141 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,43 @@ | ||
package benchmark | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"testing" | ||
|
||
"github.com/sergi/go-diff/diffmatchpatch" | ||
"github.com/ysmood/got" | ||
"github.com/ysmood/got/lib/lcs" | ||
) | ||
|
||
func BenchmarkLinesYad(b *testing.B) { | ||
// We use the same test file as https://github.com/sergi/go-diff/tree/master/testdata | ||
|
||
g := got.T(b) | ||
xs := lcs.NewLines(g.ReadFile("fixtures/speedtest1.txt").String()) | ||
ys := lcs.NewLines(g.ReadFile("fixtures/speedtest2.txt").String()) | ||
|
||
b.StartTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
xs.YadLCS(g.Context(), ys) | ||
} | ||
} | ||
|
||
func BenchmarkLinesGoogle(b *testing.B) { | ||
g := got.T(b) | ||
xs := g.ReadFile("fixtures/speedtest1.txt").String() | ||
ys := g.ReadFile("fixtures/speedtest2.txt").String() | ||
dmp := diffmatchpatch.New() | ||
|
||
b.StartTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
dmp.DiffMain(xs, ys, true) | ||
} | ||
} | ||
var x = randStr(100) | ||
var y = randStr(100) | ||
|
||
func BenchmarkRandomYad(b *testing.B) { | ||
g := got.T(b) | ||
xs := lcs.NewChars(g.ReadFile("fixtures/rand_x.txt").String()) | ||
ys := lcs.NewChars(g.ReadFile("fixtures/rand_y.txt").String()) | ||
lcs.Compress = false | ||
c := context.Background() | ||
|
||
xs := lcs.NewChars(x) | ||
ys := lcs.NewChars(y) | ||
|
||
b.StartTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
xs.YadLCS(g.Context(), ys) | ||
xs.YadLCS(c, ys) | ||
} | ||
} | ||
|
||
func BenchmarkRandomGoogle(b *testing.B) { | ||
g := got.T(b) | ||
xs := g.ReadFile("fixtures/rand_x.txt").String() | ||
ys := g.ReadFile("fixtures/rand_y.txt").String() | ||
dmp := diffmatchpatch.New() | ||
|
||
b.StartTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
dmp.DiffMain(xs, ys, false) | ||
dmp.DiffMain(x, y, false) | ||
} | ||
} | ||
|
||
func randStr(n int) string { | ||
b := make([]byte, n) | ||
_, _ = rand.Read(b) | ||
return string(b) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.