mirror of
https://github.com/xtaci/kcp-go.git
synced 2024-04-21 12:32:15 +00:00
commit a8ae293a9ddee042c35e2501f93fa5dfa2425302 Merge:bdaf81e1a84985Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 22:48:13 2020 +0800 Merge branch 'master' into autotune commitbdaf81e88eAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 22:38:31 2020 +0800 add loc commitce66a98f95Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 19:53:42 2020 +0800 lint commitad7383d8a3Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 19:05:35 2020 +0800 fix typo commitdc0fc2364cAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:47:14 2020 +0800 adjust tests commitec45b72c39Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:45:17 2020 +0800 remove obsolete decoder in listener commit827aa70e29Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:42:42 2020 +0800 use hierarchical defensive receiving strategy commitf5ca6b0e3aAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:34:30 2020 +0800 optimize condition commitff34f7683fAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 15:18:00 2020 +0800 fix test commita08b274651Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 15:13:20 2020 +0800 solve compability issue with non FEC sender commitab7596783bAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 15:02:34 2020 +0800 implements autotune in fec decoder commit260f61b3ebAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 14:34:48 2020 +0800 hack 16-bit to identify FEC from packet commit105bfec567Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 2 21:38:47 2020 +0800 add autotune
44 lines
919 B
Go
44 lines
919 B
Go
package kcp
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"math/rand"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkFECDecode(b *testing.B) {
|
|
const dataSize = 10
|
|
const paritySize = 3
|
|
const payLoad = 1500
|
|
decoder := newFECDecoder(dataSize, paritySize)
|
|
b.ReportAllocs()
|
|
b.SetBytes(payLoad)
|
|
for i := 0; i < b.N; i++ {
|
|
if rand.Int()%(dataSize+paritySize) == 0 { // random loss
|
|
continue
|
|
}
|
|
pkt := make([]byte, payLoad)
|
|
binary.LittleEndian.PutUint32(pkt, uint32(i))
|
|
if i%(dataSize+paritySize) >= dataSize {
|
|
binary.LittleEndian.PutUint16(pkt[4:], typeParity)
|
|
} else {
|
|
binary.LittleEndian.PutUint16(pkt[4:], typeData)
|
|
}
|
|
decoder.decode(pkt)
|
|
}
|
|
}
|
|
|
|
func BenchmarkFECEncode(b *testing.B) {
|
|
const dataSize = 10
|
|
const paritySize = 3
|
|
const payLoad = 1500
|
|
|
|
b.ReportAllocs()
|
|
b.SetBytes(payLoad)
|
|
encoder := newFECEncoder(dataSize, paritySize, 0)
|
|
for i := 0; i < b.N; i++ {
|
|
data := make([]byte, payLoad)
|
|
encoder.encode(data)
|
|
}
|
|
}
|