Skip to content

Commit

Permalink
Update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
acezen committed Jan 3, 2024
1 parent 85fc787 commit 051633d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 22 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: |
mkdir build
pushd build
cmake ../cpp -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON
cmake ../cpp -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_BENCHMARKS=ON
popd
- name: Cpp Format and lint
Expand Down Expand Up @@ -126,6 +126,14 @@ jobs:
make test
popd
- name: Benchmark
run: |
pushd build
export GAR_TEST_DATA=$PWD/../testing/
./graph_info_benchmark
./arrow_chunk_reader_benchmark
popd
GraphAr-centos-arrow-installed:
runs-on: ubuntu-latest
container:
Expand Down
6 changes: 4 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,12 @@ endif()
# ------------------------------------------------------------------------------
file(GLOB_RECURSE FILES_NEED_FORMAT "include/gar/*.h" "src/*.cc"
"test/*.h" "test/*.cc"
"examples/*.h" "examples/*.cc")
"examples/*.h" "examples/*.cc"
"benchmarks/*.h" "benchmarks/*.cc")
file(GLOB_RECURSE FILES_NEED_LINT "include/gar/*.h" "src/*.cc"
"test/*.h" "test/*.cc"
"examples/*.h" "examples/*.cc")
"examples/*.h" "examples/*.cc"
"benchmarks/*.h" "benchmarks/*.cc")

add_custom_target(gar-clformat
COMMAND clang-format --style=file -i ${FILES_NEED_FORMAT}
Expand Down
117 changes: 104 additions & 13 deletions cpp/benchmarks/arrow_chunk_reader_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,81 @@
#include "./benchmark_util.h"
#include "gar/graph_info.h"
#include "gar/reader/arrow_chunk_reader.h"
#include "gar/util/adj_list_type.h"

namespace GAR_NAMESPACE_INTERNAL {

template <class Reader> void ReadChunk(::benchmark::State& state, const std::shared_ptr<GraphInfo>& graph_info) {
auto maybe_reader = Reader::Make(
graph_info, state.range(0), state.range(3));
BENCHMARK_DEFINE_F(BenchmarkFixture, CreateVertexPropertyArrowChunkReader)
(::benchmark::State& state) { // NOLINT
for (auto _ : state) {
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
graph_info_, "person", "firstName");
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
}
}

BENCHMARK_DEFINE_F(BenchmarkFixture, CreateAdjListArrowChunkReader)
(::benchmark::State& state) { // NOLINT
for (auto _ : state) {
auto maybe_reader =
AdjListArrowChunkReader::Make(graph_info_, "person", "knows", "person",
AdjListType::ordered_by_source);
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
}
}

BENCHMARK_DEFINE_F(BenchmarkFixture, CreateAdjListOffsetArrowChunkReader)
(::benchmark::State& state) { // NOLINT
for (auto _ : state) {
auto maybe_reader = AdjListOffsetArrowChunkReader::Make(
graph_info_, "person", "knows", "person",
AdjListType::ordered_by_source);
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
}
}

BENCHMARK_DEFINE_F(BenchmarkFixture, CreateAdjListPropertyArrowChunkReader)
(::benchmark::State& state) { // NOLINT
for (auto _ : state) {
auto maybe_reader = AdjListPropertyArrowChunkReader::Make(
graph_info_, "person", "knows", "person", "creationDate",
AdjListType::ordered_by_source);
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
}
}

BENCHMARK_DEFINE_F(BenchmarkFixture, VertexPropertyArrowChunkReaderReadChunk)
(::benchmark::State& state) { // NOLINT
auto maybe_reader =
VertexPropertyArrowChunkReader::Make(graph_info_, "person", "firstName");
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
auto reader = maybe_reader.value();
for (auto _ : state) {
reader->seek(0);
reader->GetChunk();
reader->next_chunk();
}
}

BENCHMARK_DEFINE_F(BenchmarkFixture, AdjListArrowChunkReaderReadChunk)
(::benchmark::State& state) { // NOLINT
auto maybe_reader = AdjListArrowChunkReader::Make(
graph_info_, "person", "knows", "person", AdjListType::ordered_by_source);
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
Expand All @@ -37,20 +106,42 @@ template <class Reader> void ReadChunk(::benchmark::State& state, const std::sha
}
}

BENCHMARK_DEFINE_F(BenchmarkFixture, CreateReader)(::benchmark::State& state) {
BENCHMARK_DEFINE_F(BenchmarkFixture, AdjListOffsetArrowChunkReaderReadChunk)
(::benchmark::State& state) { // NOLINT
auto maybe_reader = AdjListOffsetArrowChunkReader::Make(
graph_info_, "person", "knows", "person", AdjListType::ordered_by_source);
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
auto reader = maybe_reader.value();
for (auto _ : state) {
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
graph_info_, state.range(0), state.range(3));
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
reader->seek(0);
reader->GetChunk();
reader->next_chunk();
}
}
BENCHMARK_REGISTER_F(BenchmarkFixture, CreateReader);

BENCHMARK_DEFINE_F(BenchmarkFixture, VertexPropertyArrowChunkReaderReadChunk)(::benchmark::State& state) {
ReadParquetChunk(state, graph_info_);
BENCHMARK_DEFINE_F(BenchmarkFixture, AdjListPropertyArrowChunkReaderReadChunk)
(::benchmark::State& state) { // NOLINT
auto maybe_reader = AdjListPropertyArrowChunkReader::Make(
graph_info_, "person", "knows", "person", "creationDate",
AdjListType::ordered_by_source);
if (maybe_reader.has_error()) {
state.SkipWithError(maybe_reader.status().message().c_str());
return;
}
auto reader = maybe_reader.value();
for (auto _ : state) {
reader->seek(0);
reader->GetChunk();
reader->next_chunk();
}
}

BENCHMARK_REGISTER_F(BenchmarkFixture, CreateVertexPropertyArrowChunkReader);
BENCHMARK_REGISTER_F(BenchmarkFixture, CreateAdjListArrowChunkReader);
BENCHMARK_REGISTER_F(BenchmarkFixture, CreateAdjListOffsetArrowChunkReader);

BENCHMARK_REGISTER_F(BenchmarkFixture, VertexPropertyArrowChunkReaderReadChunk);
} // namespace GAR_NAMESPACE_INTERNAL
9 changes: 5 additions & 4 deletions cpp/benchmarks/benchmark_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/

#include <filesystem>
#include <memory>
#include <string>

#include "benchmark/benchmark.h"

#include "gar/graph_info.h"
#include "gar/util/status.h"

#ifndef CPP_BENCHMARK_BENCHMARK_UTIL_H_
#define CPP_BENCHMARK_BENCHMARK_UTIL_H_
#ifndef CPP_BENCHMARKS_BENCHMARK_UTIL_H_
#define CPP_BENCHMARKS_BENCHMARK_UTIL_H_

namespace GAR_NAMESPACE_INTERNAL {

Expand Down Expand Up @@ -53,9 +54,9 @@ class BenchmarkFixture : public ::benchmark::Fixture {
void TearDown(const ::benchmark::State& state) override {}

protected:
std::string path_;
std::string path_;
std::shared_ptr<GraphInfo> graph_info_;
};
} // namespace GAR_NAMESPACE_INTERNAL

#endif // CPP_BENCHMARK_BENCHMARK_UTIL_H_
#endif // CPP_BENCHMARKS_BENCHMARK_UTIL_H_
6 changes: 4 additions & 2 deletions cpp/benchmarks/graph_info_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

namespace GAR_NAMESPACE_INTERNAL {

static void CreateGraphInfo(::benchmark::State& state, const std::string& path) {
static void CreateGraphInfo(::benchmark::State& state, // NOLINT
const std::string& path) {
for (auto _ : state) {
auto maybe_graph_info = GraphInfo::Load(path);
if (maybe_graph_info.has_error()) {
Expand All @@ -31,7 +32,8 @@ static void CreateGraphInfo(::benchmark::State& state, const std::string& path)
}
}

BENCHMARK_DEFINE_F(BenchmarkFixture, InitialGraphInfo)(::benchmark::State& state) {
BENCHMARK_DEFINE_F(BenchmarkFixture, InitialGraphInfo)
(::benchmark::State& state) { // NOLINT
CreateGraphInfo(state, path_);
}
BENCHMARK_REGISTER_F(BenchmarkFixture, InitialGraphInfo);
Expand Down

0 comments on commit 051633d

Please sign in to comment.