From 07ff2dc0044c51cd162e8eede7ef17d5e581a8c7 Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Mon, 16 May 2022 21:21:10 +0800 Subject: [PATCH] =?UTF-8?q?perf[protocol]:=20=E4=BD=BF=E7=94=A8=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E7=94=9F=E6=88=90=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/src/test/cpp/CMakeLists.txt | 4 +- .../cpp/{zfoocpp => cppProtocol}/ByteBuffer.h | 60 +++++++++---------- .../Packet}/ComplexObject.h | 6 +- .../Packet}/NormalObject.h | 6 +- .../{zfoocpp => cppProtocol/Packet}/ObjectA.h | 4 +- .../{zfoocpp => cppProtocol/Packet}/ObjectB.h | 2 +- .../Packet}/SimpleObject.h | 2 +- .../ProtocolManager.h | 10 ++-- protocol/src/test/cpp/main.cpp | 16 +++-- protocol/src/test/cpp/test/byte_buffer_test.h | 2 +- .../src/test/cpp/test/serialization_test.h | 4 +- protocol/src/test/cpp/test/speed_test.h | 6 +- 12 files changed, 64 insertions(+), 58 deletions(-) rename protocol/src/test/cpp/{zfoocpp => cppProtocol}/ByteBuffer.h (96%) rename protocol/src/test/cpp/{zfoocpp => cppProtocol/Packet}/ComplexObject.h (99%) rename protocol/src/test/cpp/{zfoocpp => cppProtocol/Packet}/NormalObject.h (98%) rename protocol/src/test/cpp/{zfoocpp => cppProtocol/Packet}/ObjectA.h (96%) rename protocol/src/test/cpp/{zfoocpp => cppProtocol/Packet}/ObjectB.h (97%) rename protocol/src/test/cpp/{zfoocpp => cppProtocol/Packet}/SimpleObject.h (97%) rename protocol/src/test/cpp/{zfoocpp => cppProtocol}/ProtocolManager.h (83%) diff --git a/protocol/src/test/cpp/CMakeLists.txt b/protocol/src/test/cpp/CMakeLists.txt index fc0ae73d..87d35f3e 100644 --- a/protocol/src/test/cpp/CMakeLists.txt +++ b/protocol/src/test/cpp/CMakeLists.txt @@ -6,8 +6,8 @@ set(CMAKE_CXX_STANDARD 20) set(PROJECT_MAIN cpp) # main -file(GLOB_RECURSE MAIN_SOURCES zfoocpp/*.c**) -file(GLOB_RECURSE MAIN_HEADERS zfoocpp/*.h**) +file(GLOB_RECURSE MAIN_SOURCES cppProtocol/*.c**) +file(GLOB_RECURSE MAIN_HEADERS cppProtocol/*.h**) # test file(GLOB_RECURSE TEST_SOURCES test/*.c**) diff --git a/protocol/src/test/cpp/zfoocpp/ByteBuffer.h b/protocol/src/test/cpp/cppProtocol/ByteBuffer.h similarity index 96% rename from protocol/src/test/cpp/zfoocpp/ByteBuffer.h rename to protocol/src/test/cpp/cppProtocol/ByteBuffer.h index e242a618..fafe9735 100644 --- a/protocol/src/test/cpp/zfoocpp/ByteBuffer.h +++ b/protocol/src/test/cpp/cppProtocol/ByteBuffer.h @@ -417,7 +417,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeBool(value); } } @@ -439,7 +439,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeBool(value); } } @@ -460,7 +460,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeBool(value); } } @@ -482,7 +482,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeByte(value); } } @@ -504,7 +504,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeByte(value); } } @@ -525,7 +525,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeByte(value); } } @@ -547,7 +547,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeShort(value); } } @@ -568,7 +568,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeShort(value); } } @@ -589,7 +589,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeShort(value); } } @@ -611,7 +611,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeInt(value); } } @@ -632,7 +632,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeInt(value); } } @@ -653,7 +653,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeInt(value); } } @@ -675,7 +675,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeLong(value); } } @@ -696,7 +696,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeLong(value); } } @@ -717,7 +717,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeLong(value); } } @@ -739,7 +739,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeFloat(value); } } @@ -760,7 +760,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeFloat(value); } } @@ -781,7 +781,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeFloat(value); } } @@ -803,7 +803,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeDouble(value); } } @@ -824,7 +824,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeDouble(value); } } @@ -845,7 +845,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeDouble(value); } } @@ -867,7 +867,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeChar(value); } } @@ -888,7 +888,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeChar(value); } } @@ -909,7 +909,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeChar(value); } } @@ -931,7 +931,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writeString(value); } } @@ -952,7 +952,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writeString(value); } } @@ -973,7 +973,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writeString(value); } } @@ -1282,7 +1282,7 @@ namespace zfoo { } int32_t length = array.size(); writeInt(length); - for (const auto &value : array) { + for (auto value : array) { writePacket((IPacket *) &value, protocolId); } } @@ -1307,7 +1307,7 @@ namespace zfoo { } int32_t length = list.size(); writeInt(length); - for (const auto &value : list) { + for (auto value : list) { writePacket((IPacket *) &value, protocolId); } } @@ -1332,7 +1332,7 @@ namespace zfoo { } int32_t length = set.size(); writeInt(length); - for (const auto &value : set) { + for (auto value : set) { writePacket((IPacket *) &value, protocolId); } } diff --git a/protocol/src/test/cpp/zfoocpp/ComplexObject.h b/protocol/src/test/cpp/cppProtocol/Packet/ComplexObject.h similarity index 99% rename from protocol/src/test/cpp/zfoocpp/ComplexObject.h rename to protocol/src/test/cpp/cppProtocol/Packet/ComplexObject.h index 55f1d28f..6a1f23d4 100644 --- a/protocol/src/test/cpp/zfoocpp/ComplexObject.h +++ b/protocol/src/test/cpp/cppProtocol/Packet/ComplexObject.h @@ -1,9 +1,9 @@ #ifndef ZFOO_COMPLEXOBJECT_H #define ZFOO_COMPLEXOBJECT_H -#include "zfoocpp/ByteBuffer.h" -#include "zfoocpp/ObjectA.h" -#include "zfoocpp/ObjectB.h" +#include "cppProtocol/ByteBuffer.h" +#include "cppProtocol/Packet/ObjectA.h" +#include "cppProtocol/Packet/ObjectB.h" namespace zfoo { diff --git a/protocol/src/test/cpp/zfoocpp/NormalObject.h b/protocol/src/test/cpp/cppProtocol/Packet/NormalObject.h similarity index 98% rename from protocol/src/test/cpp/zfoocpp/NormalObject.h rename to protocol/src/test/cpp/cppProtocol/Packet/NormalObject.h index ee9ec1a3..947d66fe 100644 --- a/protocol/src/test/cpp/zfoocpp/NormalObject.h +++ b/protocol/src/test/cpp/cppProtocol/Packet/NormalObject.h @@ -1,9 +1,9 @@ #ifndef ZFOO_NORMALOBJECT_H #define ZFOO_NORMALOBJECT_H -#include "zfoocpp/ByteBuffer.h" -#include "zfoocpp/ObjectA.h" -#include "zfoocpp/ObjectB.h" +#include "cppProtocol/ByteBuffer.h" +#include "cppProtocol/Packet/ObjectA.h" +#include "cppProtocol/Packet/ObjectB.h" namespace zfoo { diff --git a/protocol/src/test/cpp/zfoocpp/ObjectA.h b/protocol/src/test/cpp/cppProtocol/Packet/ObjectA.h similarity index 96% rename from protocol/src/test/cpp/zfoocpp/ObjectA.h rename to protocol/src/test/cpp/cppProtocol/Packet/ObjectA.h index aae18594..6f305efb 100644 --- a/protocol/src/test/cpp/zfoocpp/ObjectA.h +++ b/protocol/src/test/cpp/cppProtocol/Packet/ObjectA.h @@ -1,8 +1,8 @@ #ifndef ZFOO_OBJECTA_H #define ZFOO_OBJECTA_H -#include "zfoocpp/ByteBuffer.h" -#include "zfoocpp/ObjectB.h" +#include "cppProtocol/ByteBuffer.h" +#include "cppProtocol/Packet/ObjectB.h" namespace zfoo { diff --git a/protocol/src/test/cpp/zfoocpp/ObjectB.h b/protocol/src/test/cpp/cppProtocol/Packet/ObjectB.h similarity index 97% rename from protocol/src/test/cpp/zfoocpp/ObjectB.h rename to protocol/src/test/cpp/cppProtocol/Packet/ObjectB.h index 97b3da2b..8424a311 100644 --- a/protocol/src/test/cpp/zfoocpp/ObjectB.h +++ b/protocol/src/test/cpp/cppProtocol/Packet/ObjectB.h @@ -1,7 +1,7 @@ #ifndef ZFOO_OBJECTB_H #define ZFOO_OBJECTB_H -#include "zfoocpp/ByteBuffer.h" +#include "cppProtocol/ByteBuffer.h" namespace zfoo { diff --git a/protocol/src/test/cpp/zfoocpp/SimpleObject.h b/protocol/src/test/cpp/cppProtocol/Packet/SimpleObject.h similarity index 97% rename from protocol/src/test/cpp/zfoocpp/SimpleObject.h rename to protocol/src/test/cpp/cppProtocol/Packet/SimpleObject.h index 499ca26e..b267401b 100644 --- a/protocol/src/test/cpp/zfoocpp/SimpleObject.h +++ b/protocol/src/test/cpp/cppProtocol/Packet/SimpleObject.h @@ -1,7 +1,7 @@ #ifndef ZFOO_SIMPLEOBJECT_H #define ZFOO_SIMPLEOBJECT_H -#include "zfoocpp/ByteBuffer.h" +#include "cppProtocol/ByteBuffer.h" namespace zfoo { diff --git a/protocol/src/test/cpp/zfoocpp/ProtocolManager.h b/protocol/src/test/cpp/cppProtocol/ProtocolManager.h similarity index 83% rename from protocol/src/test/cpp/zfoocpp/ProtocolManager.h rename to protocol/src/test/cpp/cppProtocol/ProtocolManager.h index 3976f499..8629679c 100644 --- a/protocol/src/test/cpp/zfoocpp/ProtocolManager.h +++ b/protocol/src/test/cpp/cppProtocol/ProtocolManager.h @@ -2,11 +2,11 @@ #define ZFOO_PROTOCOLMANAGER_H #include "ByteBuffer.h" -#include "zfoocpp/ComplexObject.h" -#include "zfoocpp/NormalObject.h" -#include "zfoocpp/ObjectA.h" -#include "zfoocpp/ObjectB.h" -#include "zfoocpp/SimpleObject.h" +#include "cppProtocol/packet/ComplexObject.h" +#include "cppProtocol/packet/NormalObject.h" +#include "cppProtocol/packet/ObjectA.h" +#include "cppProtocol/packet/ObjectB.h" +#include "cppProtocol/packet/SimpleObject.h" namespace zfoo { diff --git a/protocol/src/test/cpp/main.cpp b/protocol/src/test/cpp/main.cpp index aae751d0..e158b699 100644 --- a/protocol/src/test/cpp/main.cpp +++ b/protocol/src/test/cpp/main.cpp @@ -8,11 +8,17 @@ using namespace std; int main() { - list_test::list_all_test(); - byte_buffer_test::byte_buffer_all_test(); - serialization_test::protocol_all_test(); + try { + list_test::list_all_test(); + byte_buffer_test::byte_buffer_all_test(); + serialization_test::protocol_all_test(); - speed_test::parseObject(); - speed_test::singleThreadBenchmarks(); + speed_test::parseObject(); + speed_test::singleThreadBenchmarks(); + } catch (string &e) { + cout << e << endl; + } catch (...) { + cout << "unknown" << endl; + } return 0; } diff --git a/protocol/src/test/cpp/test/byte_buffer_test.h b/protocol/src/test/cpp/test/byte_buffer_test.h index 31eb9fc0..d743fcc0 100644 --- a/protocol/src/test/cpp/test/byte_buffer_test.h +++ b/protocol/src/test/cpp/test/byte_buffer_test.h @@ -3,7 +3,7 @@ #include -#include "zfoocpp/ByteBuffer.h" +#include "cppProtocol//ByteBuffer.h" namespace byte_buffer_test { diff --git a/protocol/src/test/cpp/test/serialization_test.h b/protocol/src/test/cpp/test/serialization_test.h index 75e840c5..8546d53b 100644 --- a/protocol/src/test/cpp/test/serialization_test.h +++ b/protocol/src/test/cpp/test/serialization_test.h @@ -6,7 +6,7 @@ #include #include -#include "zfoocpp/ProtocolManager.h" +#include "cppProtocol/ProtocolManager.h" namespace serialization_test { @@ -75,7 +75,7 @@ namespace serialization_test { void complexObjectTest() { // 读取二进制文件 - ifstream file("C:\\zfoo\\protocol\\src\\test\\resources\\ComplexObject.bytes", ios::out | ios::binary); + ifstream file("../resources/ComplexObject.bytes", ios::out | ios::binary); unsigned char carray[10000]; int length = 0; while (file.read((char *) &carray[length], sizeof(unsigned char))) { diff --git a/protocol/src/test/cpp/test/speed_test.h b/protocol/src/test/cpp/test/speed_test.h index 560ae84c..c1e77aab 100644 --- a/protocol/src/test/cpp/test/speed_test.h +++ b/protocol/src/test/cpp/test/speed_test.h @@ -5,7 +5,7 @@ #include #include -#include "zfoocpp/ProtocolManager.h" +#include "cppProtocol/ProtocolManager.h" namespace speed_test { @@ -20,7 +20,7 @@ namespace speed_test { void parseObject() { // 读取二进制文件 - ifstream file("C:\\zfoo\\protocol\\src\\test\\resources\\ComplexObject.bytes", ios::out | ios::binary); + ifstream file("../resources/ComplexObject.bytes", ios::out | ios::binary); unsigned char carray[10000]; int length = 0; while (file.read((char *) &carray[length], sizeof(unsigned char))) { @@ -107,4 +107,4 @@ namespace speed_test { } -#endif \ No newline at end of file +#endif