Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed May 24, 2024
1 parent 46150da commit f0817db
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions benchmark/pb_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class ScopedTimer {

void bench(int Count) {
// init the benchmark data
stpb::BaseTypeMsg base_type_st{{},
std::numeric_limits<int32_t>::max(),
stpb::BaseTypeMsg base_type_st{std::numeric_limits<int32_t>::max(),
std::numeric_limits<int64_t>::max(),
std::numeric_limits<uint32_t>::max(),
std::numeric_limits<uint64_t>::max(),
Expand All @@ -41,8 +40,7 @@ void bench(int Count) {
pb::BaseTypeMsg base_type_msg;
SetBaseTypeMsg(base_type_st, base_type_msg);

stpb::IguanaTypeMsg iguana_type_st{{},
{std::numeric_limits<int32_t>::max()},
stpb::IguanaTypeMsg iguana_type_st{{std::numeric_limits<int32_t>::max()},
{std::numeric_limits<int64_t>::max()},
{std::numeric_limits<uint32_t>::max()},
{std::numeric_limits<uint64_t>::max()},
Expand All @@ -52,7 +50,6 @@ void bench(int Count) {
SetIguanaTypeMsg(iguana_type_st, iguana_type_msg);

stpb::RepeatBaseTypeMsg re_base_type_st{
{},
{std::numeric_limits<uint32_t>::max(),
std::numeric_limits<uint32_t>::min()},
{std::numeric_limits<uint64_t>::max(),
Expand All @@ -69,39 +66,31 @@ void bench(int Count) {
SetRepeatBaseTypeMsg(re_base_type_st, re_base_type_msg);

stpb::RepeatIguanaTypeMsg re_iguana_type_st{
{},
{{0}, {1}, {3}},
{{4}, {5}, {6}},
{{7}, {8}, {9}},
{{10}, {11}, {12}},
{{13}, {14}, {15}},
{},
{{0}, {1}, {3}}, {{4}, {5}, {6}}, {{7}, {8}, {9}},
{{10}, {11}, {12}}, {{13}, {14}, {15}}, {},
};
pb::RepeatIguanaTypeMsg re_iguana_type_msg;
SetRepeatIguanaTypeMsg(re_iguana_type_st, re_iguana_type_msg);

stpb::NestedMsg nest_st{
{},
/* base_msg */
{{}, 100, 200, 300, 400, 31.4f, 62.8, false, "World", stpb::Enum::BAZ},
{100, 200, 300, 400, 31.4f, 62.8, false, "World", stpb::Enum::BAZ},
/* repeat_base_msg */
{{{}, 1, 2, 3, 4, 5.5f, 6.6, true, "Hello", stpb::Enum::FOO},
{{}, 7, 8, 9, 10, 11.11f, 12.12, false, "Hi", stpb::Enum::BAR}},
/* iguana_type_msg */ {{}, {100}, {200}, {300}, {400}, {31}, {32}},
{{1, 2, 3, 4, 5.5f, 6.6, true, "Hello", stpb::Enum::FOO},
{7, 8, 9, 10, 11.11f, 12.12, false, "Hi", stpb::Enum::BAR}},
/* iguana_type_msg */ {{100}, {200}, {300}, {400}, {31}, {32}},
/* repeat_iguna_msg */
{{}, {{1}, {2}, {3}}, {{4}, {5}, {6}}, {{7}, {8}, {9}}},
{{{1}, {2}, {3}}, {{4}, {5}, {6}}, {{7}, {8}, {9}}},
/* repeat_repeat_base_msg */
{{{},
{1, 2, 3},
{{{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12},
{13.1, 14.2, 15.3},
{16.4, 17.5, 18.6},
{"a", "b", "c"},
{stpb::Enum::FOO, stpb::Enum::BAR, stpb::Enum::BAZ}},
{{},
{19, 20, 21},
{{19, 20, 21},
{22, 23, 24},
{25, 26, 27},
{28, 29, 30},
Expand All @@ -117,13 +106,12 @@ void bench(int Count) {
map_st.sfix64_str_map.emplace(iguana::sfixed64_t{20}, "twenty");

map_st.str_iguana_type_msg_map.emplace(
"first", stpb::IguanaTypeMsg{{}, {10}, {20}, {30}, {40}, {50}, {60}});
"first", stpb::IguanaTypeMsg{{10}, {20}, {30}, {40}, {50}, {60}});
map_st.str_iguana_type_msg_map.emplace(
"second", stpb::IguanaTypeMsg{{}, {11}, {21}, {31}, {41}, {51}, {61}});
"second", stpb::IguanaTypeMsg{{11}, {21}, {31}, {41}, {51}, {61}});

map_st.int_repeat_base_msg_map.emplace(
1, stpb::RepeatBaseTypeMsg{{},
{1, 2},
1, stpb::RepeatBaseTypeMsg{{1, 2},
{3, 4},
{5, 6},
{7, 8},
Expand All @@ -132,8 +120,7 @@ void bench(int Count) {
{"one", "two"},
{stpb::Enum::FOO, stpb::Enum::BAR}});
map_st.int_repeat_base_msg_map.emplace(
2, stpb::RepeatBaseTypeMsg{{},
{2, 3},
2, stpb::RepeatBaseTypeMsg{{2, 3},
{4, 5},
{6, 7},
{8, 9},
Expand All @@ -144,9 +131,9 @@ void bench(int Count) {
pb::MapMsg map_msg{};
SetMapMsg(map_st, map_msg);

stpb::BaseTypeMsg baseTypeMsg{{}, 100, 200, 300, 400,
31.4f, 62.8, false, "World", stpb::Enum::BAZ};
stpb::BaseOneofMsg base_one_of_st{{}, 123, baseTypeMsg, 456.78};
stpb::BaseTypeMsg baseTypeMsg{
100, 200, 300, 400, 31.4f, 62.8, false, "World", stpb::Enum::BAZ};
stpb::BaseOneofMsg base_one_of_st{123, baseTypeMsg, 456.78};
pb::BaseOneofMsg base_one_of_msg;
SetBaseOneofMsg(base_one_of_st, base_one_of_msg);

Expand Down Expand Up @@ -319,12 +306,10 @@ void bench2(int Count) {
std::string pb_str;
pb_simple.SerializeToString(&pb_str);

stpb::simple_t simple{0,
std::numeric_limits<int32_t>::max(),
stpb::simple_t simple{std::numeric_limits<int32_t>::max(),
std::numeric_limits<int32_t>::max(),
std::numeric_limits<int64_t>::max(),
std::numeric_limits<int64_t>::max(),
temp};
std::numeric_limits<int64_t>::max(), temp};
std::string sp_str;
iguana::to_pb(simple, sp_str);

Expand Down Expand Up @@ -405,7 +390,7 @@ void bench3(int Count) {
}

void bench4(int Count) {
stpb::bench_int32 st_num{0, 10, 20, 31, 42};
stpb::bench_int32 st_num{10, 20, 31, 42};
mygame::bench_int32 pb_num;
pb_num.set_a(10);
pb_num.set_b(20);
Expand Down

0 comments on commit f0817db

Please sign in to comment.