Files
kcp-go/fec_test.go
T
xtaci cd06d59cba Squashed commit of the following:
commit 0e5741b954
Author: fuli <fuli@rockx.com>
Date:   Thu Jan 4 16:21:42 2024 +0800

    use latest packet compare

commit 97999b9dc2
Author: fuli <fuli@rockx.com>
Date:   Thu Jan 4 16:07:08 2024 +0800

    face race in test

commit 446bead851
Author: fuli <fuli@rockx.com>
Date:   Thu Jan 4 16:04:42 2024 +0800

    upd

commit 570e9b006e
Author: fuli <fuli@rockx.com>
Date:   Thu Jan 4 16:03:17 2024 +0800

    revert some file

commit c665db20a5
Author: 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 commit 717b79a156.

commit 717b79a156
Author: 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 commit 681bda64d1.

commit 681bda64d1
Author: 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

commit 7974357dd0
Author: xtaci <daniel820313@gmail.com>
Date:   Thu Jan 4 00:04:06 2024 +0800

    use unix.Milli

commit 375407b80c
Author: xtaci <daniel820313@gmail.com>
Date:   Wed Jan 3 23:40:01 2024 +0800

    add passive fec
2024-01-04 22:43:12 +08:00

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)
}
}