Skip to content

Commit

Permalink
[unet-protobuf]: added perf-test
Browse files Browse the repository at this point in the history
  • Loading branch information
vpashka committed Jul 10, 2021
1 parent a53c67f commit a4680d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extensions/UNetUDP/UDPPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace uniset
// Теоретический размер данных в UDP пакете (исключая заголовки) 65507
// Желательно не вылезать за размер MTU (обычно 1500) - заголовки = 1432 байта
// т.е. надо чтобы sizeof(UDPPacket) < 1432
static const size_t MaxACount = 5000;
static const size_t MaxDCount = 5000;
static const size_t MaxACount = 2000;
static const size_t MaxDCount = 2000;
static const size_t MessageBufSize = 34700;

struct UDPMessage
Expand Down
33 changes: 33 additions & 0 deletions extensions/UNetUDP/tests/test_unet_proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <memory>
#include "UniSetTypes.h"
#include "UDPPacket.h"
#include "PassiveTimer.h"
// -----------------------------------------------------------------------------
#include "proto/unet.pb.h"
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -113,3 +114,35 @@ TEST_CASE("[UNetUDP]: crc", "[unetudp][protobuf][crc]")
REQUIRE( pack.dataCRC() != crc );
REQUIRE( pack.dataCRCWithBuf(buf, sizeof(buf)) != crc_b );
}

// -----------------------------------------------------------------------------
TEST_CASE("[UNetUDP]: perf test", "[unetudp][protobuf][perf]")
{
uint8_t buf[uniset::UniSetUDP::MessageBufSize];

UniSetUDP::UDPMessage pack;
REQUIRE(pack.isOk());
pack.setNodeID(100);
pack.setProcID(100);
pack.setNum(1);

for( size_t i=0; i<uniset::UniSetUDP::MaxACount; i++ ) {
pack.addAData(i,i);
pack.addDData(i,true);
}

UniSetUDP::UDPMessage pack2;

PassiveTimer pt;

for( int i=0; i<100000; i++ ) {
// pack
// uint16_t crc = pasck.dataCRC();
auto ret = pack.serializeToArray(buf, sizeof(buf));

// unpack
pack2.initFromBuffer(buf, ret);
}

cerr << "perf: " << pt.getCurrent() << " msec" << endl;
}

0 comments on commit a4680d6

Please sign in to comment.