mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-02 19:37:40 +03:00
Fix checksum bench
This commit is contained in:
parent
7f3343169a
commit
57aba1a5c4
4 changed files with 7 additions and 5 deletions
|
@ -28,6 +28,6 @@ func BenchmarkGChecksum(b *testing.B) {
|
||||||
}
|
}
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
checksum.Checksum(packet[i%1000], 0)
|
checksum.ChecksumDefault(packet[i%1000], 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,3 +38,8 @@ func Combine(a, b uint16) uint16 {
|
||||||
v := uint32(a) + uint32(b)
|
v := uint32(a) + uint32(b)
|
||||||
return uint16(v + v>>16)
|
return uint16(v + v>>16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChecksumDefault(buf []byte, initial uint16) uint16 {
|
||||||
|
s, _ := calculateChecksum(buf, false, initial)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,5 @@ package checksum
|
||||||
//
|
//
|
||||||
// The initial checksum must have been computed on an even number of bytes.
|
// The initial checksum must have been computed on an even number of bytes.
|
||||||
func Checksum(buf []byte, initial uint16) uint16 {
|
func Checksum(buf []byte, initial uint16) uint16 {
|
||||||
s, _ := calculateChecksum(buf, false, initial)
|
return ChecksumDefault(buf, initial)
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
//go:build !amd64
|
|
||||||
|
|
||||||
// Copyright 2023 The gVisor Authors.
|
// Copyright 2023 The gVisor Authors.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue