Skip to content

Commit

Permalink
🎨 Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
raidgar98 committed Feb 5, 2023
1 parent 4bd958b commit 232af52
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 135 deletions.
19 changes: 6 additions & 13 deletions benchmarks/benchmark_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <fc_benchmark_controller.hpp>
#include <serek_benchmark_controller.hpp>

using ll = trantor::Logger::LogLevel;
using ll = trantor::Logger::LogLevel;
using score_set_t = std::pair<benchmark_scores_storage_t, benchmark_scores_storage_t>;
using score_map_type = std::pair<std::string, score_set_t>;

Expand All @@ -41,13 +41,7 @@ trantor::LogStream& log(const size_t line_no, const char* function = "main")
*
* @return score_set_t initialized pair of two shared pointers pointing to initialized vectors
*/
score_set_t create_pair()
{
return std::make_pair(
std::make_shared<benchmark_scores_storage_t::element_type>(),
std::make_shared<benchmark_scores_storage_t::element_type>()
);
}
score_set_t create_pair() { return std::make_pair(std::make_shared<benchmark_scores_storage_t::element_type>(), std::make_shared<benchmark_scores_storage_t::element_type>()); }

int main()
{
Expand All @@ -67,7 +61,7 @@ int main()
.setThreadNum(1)
.run();

for(const auto& kv : scores)
for(const auto& kv: scores)
{
// verify is amount of serializations and deserializations were same
if(kv.second.first->size() != kv.second.second->size())
Expand All @@ -81,8 +75,8 @@ int main()
log<ll::kWarn>(__LINE__) << "Amount of performed calls is lower than expected number of calls: " << calls << " < " << amount_of_calls;

// open file
const std::string filename{ kv.first + "_scores.csv" };
std::ofstream out_file{ filename };
const std::string filename{kv.first + "_scores.csv"};
std::ofstream out_file{filename};
if(!out_file.good())
{
// handle errors
Expand All @@ -95,8 +89,7 @@ int main()
out_file << "probe no.,deserialization time in ms,serialization time in ms\n";

// write data
for(size_t i{0ul}; i < kv.second.first->size(); ++i)
out_file << i << ',' << kv.second.first->at(i) << ',' << kv.second.second->at(i) << '\n';
for(size_t i{0ul}; i < kv.second.first->size(); ++i) out_file << i << ',' << kv.second.first->at(i) << ',' << kv.second.second->at(i) << '\n';

// flush data that has been written
out_file << std::flush;
Expand Down
40 changes: 13 additions & 27 deletions benchmarks/controllers/benchmark_controllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void drogon_benchmark_controller::deserialize(model_t& out, const std::string_vi
serek::require(false);
}

const auto deserial_A = [&is_not_null, &null](const Json::Value& json, drogon_model::A& o)
{
const auto deserial_A = [&is_not_null, &null](const Json::Value& json, drogon_model::A& o) {
auto x = json.get("a1", null);
is_not_null(x);
o.a1 = x.asBool();
Expand All @@ -61,24 +60,21 @@ void drogon_benchmark_controller::deserialize(model_t& out, const std::string_vi
o.a5 = x.asDouble();
};

const auto deserial_B = [&is_not_null, &null, &deserial_A](const Json::Value& json, drogon_model::B& o)
{
const auto deserial_B = [&is_not_null, &null, &deserial_A](const Json::Value& json, drogon_model::B& o) {
auto x = json.get("b1", null);
is_not_null(x);
o.b1.reserve(x.size());
for(const auto& it : x)
o.b1.emplace_back(it.asInt());
for(const auto& it: x) o.b1.emplace_back(it.asInt());

x = json.get("b2", null);
is_not_null(x);
o.b2.reserve(x.size());
for(const auto& it : x)
o.b2.emplace_back(it.asDouble());
for(const auto& it: x) o.b2.emplace_back(it.asDouble());

x = json.get("b3", null);
is_not_null(x);
o.b3.reserve(x.size());
for(const auto& it : x)
for(const auto& it: x)
{
auto& a = o.b3.emplace_back();
deserial_A(it, a);
Expand All @@ -101,30 +97,26 @@ void drogon_benchmark_controller::serialize(const model_t& in, std::string& out)
{
Json::Value output;

const auto serial_A = [](Json::Value& json, const drogon_model::A& in)
{
const auto serial_A = [](Json::Value& json, const drogon_model::A& in) {
json["a1"] = in.a1;
json["a2"] = in.a2;
json["a3"] = in.a3;
json["a4"] = in.a4;
json["a5"] = in.a5;
};

const auto serial_B = [&serial_A](Json::Value& json, const drogon_model::B& in)
{
const auto serial_B = [&serial_A](Json::Value& json, const drogon_model::B& in) {
json["b1"] = Json::Value(Json::ValueType::arrayValue);
json["b1"].resize(in.b1.size());
for(const auto& it : in.b1)
json["b1"].append(it);
for(const auto& it: in.b1) json["b1"].append(it);

json["b2"] = Json::Value(Json::ValueType::arrayValue);
json["b2"].resize(in.b2.size());
for(const auto& it : in.b2)
json["b2"].append(it);
for(const auto& it: in.b2) json["b2"].append(it);

json["b3"] = Json::Value(Json::ValueType::arrayValue);
json["b3"].resize(in.b3.size());
for(const auto& it : in.b3)
for(const auto& it: in.b3)
{
Json::Value it_result;
serial_A(it_result, it);
Expand All @@ -151,7 +143,7 @@ void drogon_benchmark_controller::serialize(const model_t& in, std::string& out)
void fc_benchmark_controller::deserialize(model_t& out, const std::string_view in) const
{
const auto& variant = fc::json::from_string(std::string{in.data(), in.size()});
const auto& obj = variant.get_object();
const auto& obj = variant.get_object();
fc::reflector<model_t>::visit(fc::from_variant_visitor<model_t>(obj, out, 10));
}

Expand All @@ -162,15 +154,9 @@ void fc_benchmark_controller::serialize(const model_t& in, std::string& out) con
out = fc::json::to_string(mvo);
}

void serek_benchmark_controller::deserialize(model_t& out, const std::string_view in) const
{
serek::deserial::json::deserialize<model_t>(in, out);
}
void serek_benchmark_controller::deserialize(model_t& out, const std::string_view in) const { serek::deserial::json::deserialize<model_t>(in, out); }

void serek_benchmark_controller::serialize(const model_t& in, std::string& out) const
{
out = serek::serial::json::serialize(in);
}
void serek_benchmark_controller::serialize(const model_t& in, std::string& out) const { out = serek::serial::json::serialize(in); }

std::string drogon_benchmark_controller::controller_path() { return "/drogon"; }
std::string fc_benchmark_controller::controller_path() { return "/fc"; }
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/controllers/drogon_benchmark_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace drogon_model
A c1{};
B c2{};
};
}
} // namespace drogon_model

struct drogon_benchmark_controller : public base_benchmark_controller<drogon_benchmark_controller, typename drogon_model::C>
{
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/controllers/fc_benchmark_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace fc_model_t
A c1{};
B c2{};
};
}
} // namespace fc_model_t

struct fc_benchmark_controller : public base_benchmark_controller<fc_benchmark_controller, typename fc_model_t::C>
{
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/controllers/serek_benchmark_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace serek_model_t

struct B_impl
{
serek::ffield<std::vector<int> > b1{};
serek::field<&B_impl::b1, std::vector<double> > b2{};
serek::field<&B_impl::b2, std::vector<A> > b3{};
serek::ffield<std::vector<int>> b1{};
serek::field<&B_impl::b1, std::vector<double>> b2{};
serek::field<&B_impl::b2, std::vector<A>> b3{};
};
using B = serek::pack<&B_impl::b3>;

Expand All @@ -40,7 +40,7 @@ namespace serek_model_t
serek::field<&C_impl::c1, B> c2{};
};
using C = serek::pack<&C_impl::c2>;
}
} // namespace serek_model_t

struct serek_benchmark_controller : public base_benchmark_controller<serek_benchmark_controller, typename serek_model_t::C>
{
Expand Down
13 changes: 8 additions & 5 deletions include/serek/json/deserial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ namespace serek
namespace
{
template<reqs::integer_type_req Any>
void fill(Any& output, const serek::str_v value) { output = static_cast<Any>(std::atoll(value.data())); }
void fill(Any& output, const serek::str_v value)
{
output = static_cast<Any>(std::atoll(value.data()));
}

template<reqs::floating_type_req Any>
void fill(Any& output, const serek::str_v value)
Expand Down Expand Up @@ -91,7 +94,7 @@ namespace serek

// this is fundamental types deserialization
template<reqs::visitor_req vis_t, typename Any>
requires serek::requirements::fundamental_req<Any> || reqs::string_type_req<Any>
requires serek::requirements::fundamental_req<Any> || reqs::string_type_req<Any>
void deserial(visitor_with_stacked_names_and_tokenized_json& json, Any* output)
{
serek::require(output);
Expand All @@ -112,7 +115,7 @@ namespace serek
}

template<reqs::visitor_req vis_t, typename element_t>
requires serek::requirements::fundamental_req<element_t> || reqs::string_type_req<element_t>
requires serek::requirements::fundamental_req<element_t> || reqs::string_type_req<element_t>
void deserial_array_element(json_tokenizer::result_t in, element_t& out)
{
serek::require<std::equal_to>(in->element_type, json_element_t::FUNDAMENTAL_TYPE);
Expand All @@ -130,15 +133,15 @@ namespace serek

// this is array deserialization
template<reqs::visitor_req vis_t, template<typename T, typename... Argv> typename collection_t, typename element_t, typename... other_container_args>
requires reqs::iterable_req<collection_t<element_t, other_container_args...>>
requires reqs::iterable_req<collection_t<element_t, other_container_args...>>
void deserial(visitor_with_stacked_names_and_tokenized_json& json, collection_t<element_t, other_container_args...>* output)
{
serek::require(output);

const auto json_iterable = json.pop_for_key(json.top());
serek::require<std::equal_to>(json_iterable->element_type, json_element_t::ARRAY_TYPE);

const size_t pre_reserve_size{ json_iterable->array.size() };
const size_t pre_reserve_size{json_iterable->array.size()};
output->reserve(pre_reserve_size);
for(auto it: json_iterable->array)
{
Expand Down
4 changes: 2 additions & 2 deletions include/serek/json/serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace serek
}

template<reqs::visitor_req vis_t, typename Any>
requires serek::requirements::fundamental_req<Any> || reqs::string_type_req<Any>
requires serek::requirements::fundamental_req<Any> || reqs::string_type_req<Any>
void serial(vis_t& vis, stream_holder& out, const Any* obj)
{
serek::require(obj);
Expand All @@ -118,7 +118,7 @@ namespace serek
}

template<reqs::visitor_req vis_t, typename element_t>
requires serek::requirements::fundamental_req<element_t> || reqs::string_type_req<element_t>
requires serek::requirements::fundamental_req<element_t> || reqs::string_type_req<element_t>
void serial_array_element(vis_t&, stream_holder& out, const element_t& any)
{
out.put_to_stream(any);
Expand Down
Loading

0 comments on commit 232af52

Please sign in to comment.