123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- // Copyright © 2021 Jeffrey H. Johnson <trnsz@pobox.com>.
- // Copyright © 2015 Daniel Fu <daniel820313@gmail.com>.
- // Copyright © 2019 Loki 'l0k18' Verloren <stalker.loki@protonmail.ch>.
- // Copyright © 2021 Gridfinity, LLC. <admin@gridfinity.com>.
- //
- // All rights reserved.
- //
- // All use of this code is governed by the MIT license.
- // The complete license is available in the LICENSE file.
- package gfcp_test
- import (
- "encoding/binary"
- "math/rand"
- "testing"
- "github.com/johnsonjh/gfcp"
- )
- func BenchmarkFECDecode1500(
- b *testing.B,
- ) {
- const (
- dataSize = 10
- paritySize = 3
- payLoad = 1500
- )
- decoder := gfcp.NewFECDecoder(
- 1024,
- dataSize,
- paritySize,
- )
- b.ReportAllocs()
- b.SetBytes(
- payLoad,
- )
- for i := 0; i < b.N; i++ {
- if rand.Int()%(dataSize+paritySize) == 0 {
- continue
- }
- pkt := make(
- []byte,
- payLoad,
- )
- binary.LittleEndian.PutUint32(
- pkt,
- uint32(i),
- )
- if i%(dataSize+paritySize) >= dataSize {
- binary.LittleEndian.PutUint16(
- pkt[4:],
- gfcp.KTypeParity,
- )
- } else {
- binary.LittleEndian.PutUint16(
- pkt[4:],
- gfcp.KTypeData,
- )
- }
- decoder.Decode(
- pkt,
- )
- }
- }
- func BenchmarkFECEncode1500(
- b *testing.B,
- ) {
- const dataSize = 10
- const paritySize = 3
- const payLoad = 1500
- b.ReportAllocs()
- b.SetBytes(
- payLoad,
- )
- Encoder := gfcp.NewFECEncoder(
- dataSize,
- paritySize,
- 0,
- )
- for i := 0; i < b.N; i++ {
- data := make(
- []byte,
- payLoad,
- )
- Encoder.Encode(
- data,
- )
- }
- }
- func BenchmarkFECDecode9000(
- b *testing.B,
- ) {
- const (
- dataSize = 10
- paritySize = 3
- payLoad = 9000
- )
- decoder := gfcp.NewFECDecoder(
- 1024,
- dataSize,
- paritySize,
- )
- b.ReportAllocs()
- b.SetBytes(
- payLoad,
- )
- for i := 0; i < b.N; i++ {
- if rand.Int()%(dataSize+paritySize) == 0 {
- continue
- }
- pkt := make(
- []byte,
- payLoad,
- )
- binary.LittleEndian.PutUint32(
- pkt,
- uint32(i),
- )
- if i%(dataSize+paritySize) >= dataSize {
- binary.LittleEndian.PutUint16(
- pkt[4:],
- gfcp.KTypeParity,
- )
- } else {
- binary.LittleEndian.PutUint16(
- pkt[4:],
- gfcp.KTypeData,
- )
- }
- decoder.Decode(
- pkt,
- )
- }
- }
- func BenchmarkFECEncode9000(
- b *testing.B,
- ) {
- const dataSize = 10
- const paritySize = 3
- const payLoad = 9000
- b.ReportAllocs()
- b.SetBytes(
- payLoad,
- )
- Encoder := gfcp.NewFECEncoder(
- dataSize,
- paritySize,
- 0,
- )
- for i := 0; i < b.N; i++ {
- data := make(
- []byte,
- payLoad,
- )
- Encoder.Encode(
- data,
- )
- }
- }
|