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 all 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.

)
2 changes: 1 addition & 1 deletion benchmark/alt_bn_128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <benchmark.hpp>

namespace benchmark {
namespace eosio::benchmark {

using bytes = std::vector<char>;
using g1g2_pair = std::vector<std::string>;
Expand Down
11 changes: 7 additions & 4 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <benchmark.hpp>

namespace benchmark {
namespace eosio::benchmark {

// update this map when a new feature is supported
// key is the name and value is the function doing benchmarking
Expand All @@ -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 @@ -46,10 +47,10 @@ void print_results(std::string name, uint32_t runs, uint64_t total, uint64_t min
std::cout.imbue(std::locale(""));
std::cout
<< std::setw(name_width) << std::left << name
<< std::setw(runs_width) << runs
// std::fixed for not printing 1234 in 1.234e3.
// setprecision(0) for not printing fractions
<< std::right << std::fixed << std::setprecision(0)
<< std::setw(runs_width) << runs
<< std::setw(time_width) << total/runs << std::setw(ns_width) << " ns"
<< std::setw(time_width) << min << std::setw(ns_width) << " ns"
<< std::setw(time_width) << max << std::setw(ns_width) << " ns"
Expand All @@ -62,8 +63,10 @@ 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) {
uint64_t total{0};
uint64_t min{std::numeric_limits<uint64_t>::max()};
uint64_t max{0};

for (auto i = 0U; i < num_runs; ++i) {
auto start_time = std::chrono::high_resolution_clock::now();
Expand Down
6 changes: 4 additions & 2 deletions benchmark/benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include <functional>
#include <map>
#include <vector>
#include <limits>

#include <fc/crypto/hex.hpp>

namespace benchmark {
namespace eosio::benchmark {
using bytes = std::vector<char>;

void set_num_runs(uint32_t runs);
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);

} // benchmark
2 changes: 1 addition & 1 deletion benchmark/blake2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <benchmark.hpp>

namespace benchmark {
namespace eosio::benchmark {

void blake2_benchmarking() {
uint32_t _rounds = 0x0C;
Expand Down
Loading