Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ydot13 committed Nov 6, 2022
0 parents commit 5876ce9
Show file tree
Hide file tree
Showing 19 changed files with 2,454 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "FlameGraph"]
path = FlameGraph
url = [email protected]:brendangregg/FlameGraph.git
[submodule "protobuf"]
path = protobuf
url = [email protected]:protocolbuffers/protobuf.git
[submodule "googletest"]
path = googletest
url = [email protected]:google/googletest.git
[submodule "benchmark"]
path = benchmark
url = [email protected]:google/benchmark.git
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.22)

set(PROTO_DIR ${CMAKE_CURRENT_LIST_DIR}/protobuf)
set(PROTO_MSG ${CMAKE_CURRENT_LIST_DIR}/messages)

add_subdirectory(proto_gen)
add_subdirectory(bench)

add_subdirectory(protobuf)
add_subdirectory(googletest)
add_subdirectory(benchmark)
1 change: 1 addition & 0 deletions FlameGraph
Submodule FlameGraph added at d9fcc2
7 changes: 7 additions & 0 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
project(bench)

add_executable(${PROJECT_NAME})

target_sources(${PROJECT_NAME} PRIVATE main.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark gen_proto_lib protobuf::libprotobuf)
75 changes: 75 additions & 0 deletions bench/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "messge.pb.h"
#include <benchmark/benchmark.h>
#include <gen_data.h>
#include <fstream>

template <typename T>
class TSingletone {
public:
template<class... TArgs>
TSingletone(TArgs... args) {
if (val == nullptr) {
val = new T(std::forward(args)...);
}
}

T* operator*() {
return val;
}

static T* val;
};

template<class T>
T* TSingletone<T>::val = nullptr;


class TEnvHolder {
public:
TEnvHolder() {
// Init

NGenProto::TGenOpts opts;
opts.NumsCount = 100;
opts.StringsCount = 100;
opts.StringSize = 100;
opts.FloatCount = 100;
opts.FilesCount = 2000;
opts.SetsOfFilesCount = 100;

report = NGenProto::GenReport(opts);

std::string out;
report.SerializeToString(&out);
}

tutorial::TReport report;
};

static void BM_ParseProtoFromFile(benchmark::State& state) {

const auto& env = *TSingletone<TEnvHolder>();
for (auto _ : state) {
std::ifstream in("out.txt");

tutorial::TReport a;
tutorial::TReport res;

a.ParseFromIstream(&in);

std::sort(a.mutable_setsoffiles()->begin(), a.mutable_setsoffiles()->end(),
[](const auto& a, const auto& b) {return a.hash() > b.hash();}
);

for (size_t i = 0; i < a.setsoffiles_size() / 2; i++) {
*res.add_setsoffiles() = a.setsoffiles(i);
}

std::ofstream out("res.txt");
res.SerializeToOstream(&out);
}

}
// Register the function as a benchmark
BENCHMARK(BM_ParseProtoFromFile);
BENCHMARK_MAIN();
1 change: 1 addition & 0 deletions benchmark
Submodule benchmark added at 398a8a
3 changes: 3 additions & 0 deletions flame_from_bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sudo perf record -g ./build/bench/bench
sudo perf script > perf.script
./FlameGraph/stackcollapse-perf.pl perf.script | ./FlameGraph/flamegraph.pl > flamegraph.svg
1 change: 1 addition & 0 deletions gen_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./build/proto_gen/proto_gen --seed=13 --nums_cnt=100 --strings_cnt=100 --string_size=1000 --float_cnt=10 --files_cnt=100 --sets_cnt=100 --out=./out.txt
1 change: 1 addition & 0 deletions googletest
Submodule googletest added at a4f02e
Loading

0 comments on commit 5876ce9

Please sign in to comment.