-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5876ce9
Showing
19 changed files
with
2,454 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Submodule FlameGraph
added at
d9fcc2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Submodule googletest
added at
a4f02e
Oops, something went wrong.