Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: qupeng <[email protected]>
  • Loading branch information
hicqu committed Sep 12, 2023
1 parent 3d22762 commit 519a4cc
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions cdc/puller/frontier/frontier_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,25 @@ func toCMPBytes(i int) []byte {
return []byte(s)
}

func BenchmarkSpanForwardAndFrontier(b *testing.B) {
tests := []struct {
order string
regions int
rounds int
}{
{"random", 900_000, 10},
{"random", 400_000, 10},
{"ordered", 900_000, 10},
{"ordered", 400_000, 10},
}
func BenchmarkSpanForwardAndFrontier_random_900k_10(b *testing.B) {
benchmarkSpanForwardAndFrontier(b, "random", 900_000, 10)
}

for _, test := range tests {
order := test.order
regions := test.regions
rounds := test.rounds
func BenchmarkSpanForwardAndFrontier_ordered_900k_10(b *testing.B) {
benchmarkSpanForwardAndFrontier(b, "ordered", 900_000, 10)
}

func BenchmarkSpanForwardAndFrontier_random_400k_10(b *testing.B) {
benchmarkSpanForwardAndFrontier(b, "random", 400_000, 10)
}

func BenchmarkSpanForwardAndFrontier_ordered_400k_10(b *testing.B) {
benchmarkSpanForwardAndFrontier(b, "ordered", 400_000, 10)
}

func benchmarkSpanForwardAndFrontier(b *testing.B, order string, regions, rounds int) {
for i := 0; i < b.N; i++ {
b.StopTimer()
spans := make([]tablepb.Span, 0, regions)
for i := 0; i < regions; i++ {
span := tablepb.Span{StartKey: toCMPBytes(i), EndKey: toCMPBytes(i + 1)}
Expand All @@ -65,19 +67,19 @@ func BenchmarkSpanForwardAndFrontier(b *testing.B) {
}
}

b.ResetTimer()
b.Run(fmt.Sprintf("%s-%d(region)-%d(round)", order, regions, rounds), func(b *testing.B) {
for i := 0; i < regions*rounds; i++ {
offset := offsets[i]
span := spans[offset]
if spanz.IsSubSpan(span, totalSpan) {
f.Forward(offset, span, offset)
if i%regions == 0 {
f.Frontier()
}
b.StartTimer()
start := time.Now()
for i := 0; i < regions*rounds; i++ {
offset := offsets[i]
span := spans[offset]
if spanz.IsSubSpan(span, totalSpan) {
f.Forward(offset, span, offset)
if i%regions == 0 {
f.Frontier()
}
}
})
}
b.Logf("finishes a round, time in ms: %d", time.Since(start).Milliseconds())
}
}

Expand Down

0 comments on commit 519a4cc

Please sign in to comment.