mirror of
https://github.com/xtaci/kcp-go.git
synced 2024-04-21 12:32:15 +00:00
commit0e5741b954Author: fuli <fuli@rockx.com> Date: Thu Jan 4 16:21:42 2024 +0800 use latest packet compare commit97999b9dc2Author: fuli <fuli@rockx.com> Date: Thu Jan 4 16:07:08 2024 +0800 face race in test commit446bead851Author: fuli <fuli@rockx.com> Date: Thu Jan 4 16:04:42 2024 +0800 upd commit570e9b006eAuthor: fuli <fuli@rockx.com> Date: Thu Jan 4 16:03:17 2024 +0800 revert some file commitc665db20a5Author: fuli <fuli@rockx.com> Date: Thu Jan 4 15:59:16 2024 +0800 Revert "Revert "1. simplify readloop_xxx files & tx_xxx files by merging"" This reverts commit717b79a156. commit717b79a156Author: fuli <fuli@rockx.com> Date: Thu Jan 4 15:58:30 2024 +0800 Revert "1. simplify readloop_xxx files & tx_xxx files by merging" This reverts commit681bda64d1. commit681bda64d1Author: fuli <fuli@rockx.com> Date: Thu Jan 4 15:54:29 2024 +0800 1. simplify readloop_xxx files & tx_xxx files by merging 2. fix the race in owned packet test commit7974357dd0Author: xtaci <daniel820313@gmail.com> Date: Thu Jan 4 00:04:06 2024 +0800 use unix.Milli commit375407b80cAuthor: xtaci <daniel820313@gmail.com> Date: Wed Jan 3 23:40:01 2024 +0800 add passive fec
44 lines
929 B
Go
44 lines
929 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, 200)
|
|
for i := 0; i < b.N; i++ {
|
|
data := make([]byte, payLoad)
|
|
encoder.encode(data, 200)
|
|
}
|
|
}
|