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 732d644 commit d9a0a80
Showing 1 changed file with 33 additions and 0 deletions.
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 d9a0a80

Please sign in to comment.