Skip to content

Commit fcb4557

Browse files
committed
Fix checksum bench
1 parent 7fcd910 commit fcb4557

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

internal/checksum_test/sum_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ func BenchmarkGChecksum(b *testing.B) {
2828
}
2929
b.ResetTimer()
3030
for i := 0; i < b.N; i++ {
31-
checksum.Checksum(packet[i%1000], 0)
31+
checksum.ChecksumDefault(packet[i%1000], 0)
3232
}
3333
}

internal/gtcpip/checksum/checksum.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ func Combine(a, b uint16) uint16 {
3838
v := uint32(a) + uint32(b)
3939
return uint16(v + v>>16)
4040
}
41+
42+
func ChecksumDefault(buf []byte, initial uint16) uint16 {
43+
s, _ := calculateChecksum(buf, false, initial)
44+
return s
45+
}

internal/gtcpip/checksum/checksum_default.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ package checksum
88
//
99
// The initial checksum must have been computed on an even number of bytes.
1010
func Checksum(buf []byte, initial uint16) uint16 {
11-
s, _ := calculateChecksum(buf, false, initial)
12-
return s
11+
return ChecksumDefault(buf, initial)
1312
}

0 commit comments

Comments
 (0)