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

[5.0] Benchmark BLS host functions #1884

Merged
merged 12 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
file(GLOB BENCHMARK "*.cpp")
add_executable( benchmark ${BENCHMARK} )

target_link_libraries( benchmark fc Boost::program_options bn256)
target_link_libraries( benchmark eosio_testing fc Boost::program_options bn256)
target_include_directories( benchmark PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}/../unittests/include"
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to fix this now (or even when merging to main) but we should try to avoid these sort of declarations. We probably want a target similar to eosio_testing_contracts,

configure_file(contracts.hpp.in include/testing_contracts/contracts.hpp ESCAPE_QUOTES)
add_library(eosio_testing_contracts INTERFACE)
target_include_directories(eosio_testing_contracts INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include/testing_contracts)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @spoonincode. I was doing the cleos set code issue yesterday and not getting around with this. As the PR has already merged into 5.0, for cleaner tracking, I will merge the PR to main as is, and use your suggested way later.

)
19 changes: 15 additions & 4 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ std::map<std::string, std::function<void()>> features {
{ "key", key_benchmarking },
{ "hash", hash_benchmarking },
{ "blake2", blake2_benchmarking },
{ "bls", bls_benchmarking }
};

// values to control cout format
Expand Down Expand Up @@ -62,10 +63,20 @@ bytes to_bytes(const std::string& source) {
return output;
};

void benchmarking(std::string name, const std::function<void()>& func) {
uint64_t total {0}, min {std::numeric_limits<uint64_t>::max()}, max {0};
void benchmarking(const std::string& name,
const std::function<void()>& func,
uint32_t max_num_runs) {

for (auto i = 0U; i < num_runs; ++i) {
uint64_t total{0};
uint64_t min{std::numeric_limits<uint64_t>::max()};
uint64_t max{0};

// some benchmarked functions are expensive and run in a transaction
// (like BLS pairing). Limit actual number of runs to the function
// specific maximum such that transaction deadline is not exceeded.
uint32_t actual_num_runs = (num_runs > max_num_runs) ? max_num_runs : num_runs;

for (auto i = 0U; i < actual_num_runs; ++i) {
auto start_time = std::chrono::high_resolution_clock::now();
func();
auto end_time = std::chrono::high_resolution_clock::now();
Expand All @@ -76,7 +87,7 @@ void benchmarking(std::string name, const std::function<void()>& func) {
max = std::max(max, duration);
}

print_results(name, num_runs, total, min, max);
print_results(name, actual_num_runs, total, min, max);
}

} // benchmark
4 changes: 3 additions & 1 deletion benchmark/benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <functional>
#include <map>
#include <vector>
#include <limits>

#include <fc/crypto/hex.hpp>

Expand All @@ -19,7 +20,8 @@ void modexp_benchmarking();
void key_benchmarking();
void hash_benchmarking();
void blake2_benchmarking();
void bls_benchmarking();

void benchmarking(std::string name, const std::function<void()>& func);
void benchmarking(const std::string& name, const std::function<void()>& func, uint32_t max_num_runs = std::numeric_limits<uint32_t>::max());

} // benchmark
Loading
Loading