Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Benchmark commit function #4178

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(commit_bench)
add_subdirectory(decrypt_bench)
add_subdirectory(ipa_bench)
add_subdirectory(pippenger_bench)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Each source represents a separate benchmark suite
set(BENCHMARK_SOURCES
commit.bench.cpp
)

# Required libraries for benchmark suites
set(LINKED_LIBRARIES
commitment_schemes
benchmark::benchmark
)

# Add executable and custom target for each suite, e.g. ultra_honk_bench
foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES})
get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension
add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE})
target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES})
add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endforeach()
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#include "barretenberg/commitment_schemes/commitment_key.hpp"
#include <benchmark/benchmark.h>

namespace bb {

template <typename Curve>
std::shared_ptr<honk::pcs::CommitmentKey<Curve>> create_commitment_key(const size_t num_points)
{
std::string srs_path;
if constexpr (std::same_as<Curve, curve::BN254>) {
srs_path = "../srs_db/ignition";
} else {
static_assert(std::same_as<Curve, curve::Grumpkin>);
srs_path = "../srs_db/grumpkin";
}
std::shared_ptr<bb::srs::factories::CrsFactory<Curve>> crs_factory(
new bb::srs::factories::FileCrsFactory<Curve>(srs_path, num_points));
return std::make_shared<honk::pcs::CommitmentKey<Curve>>(num_points, crs_factory);
}

constexpr size_t MAX_LOG_NUM_POINTS = 24;
constexpr size_t MAX_NUM_POINTS = 1 << 24;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to use MAX_LOG_NUM_POINTS here instead of 24?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes should have done, thanks


auto key = create_commitment_key<curve::BN254>(MAX_NUM_POINTS);

template <typename Curve> void bench_commit(::benchmark::State& state)
{
const size_t num_points = 1 << state.range(0);
const auto polynomial = Polynomial<typename Curve::ScalarField>(num_points);
for (auto _ : state) {
benchmark::DoNotOptimize(key->commit(polynomial));
}
}

BENCHMARK(bench_commit<curve::BN254>)->DenseRange(10, MAX_LOG_NUM_POINTS)->Unit(benchmark::kMillisecond);

} // namespace bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
7 changes: 7 additions & 0 deletions barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ template <typename Fr> class Polynomial {
std::size_t size() const { return size_; }
std::size_t capacity() const { return size_ + MAXIMUM_COEFFICIENT_SHIFT; }

static Polynomial random(const size_t num_coeffs)
{
Polynomial p(num_coeffs);
std::generate_n(p.begin(), num_coeffs, []() { return Fr::random_element(); });
return p;
}

private:
// allocate a fresh memory pointer for backing memory
// DOES NOT initialize memory
Expand Down