|
| 1 | +#include "implementations.h" |
| 2 | +#include <benchmark/benchmark.h> |
| 3 | +#include <filesystem> |
| 4 | +#include <print> |
| 5 | +#include <string> |
| 6 | + |
| 7 | +namespace s3b { |
| 8 | + |
| 9 | +static void benchmark_init_client(::benchmark::State &state, s3b::implementation impl) { |
| 10 | + const std::string access_ = "minio_access"; |
| 11 | + const std::string secret_ = "minio_secret"; |
| 12 | + const std::string endpoint_ = "127.0.0.1:9000"; |
| 13 | + for (auto _ : state) { |
| 14 | + ::benchmark::DoNotOptimize(impl.init_client("minio_access", "minio_secret", "127.0.0.1:9000")); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +static void benchmark_create_bucket(::benchmark::State &state, s3b::implementation impl) { |
| 19 | + // TODO(cristian): Client handler should be stored on the implementation |
| 20 | + // struct so that we only have one client at a time initialized, shouldn't |
| 21 | + // affect the benches but who knows |
| 22 | + bench::ClientHandle handle = impl.init_client("minio_access", "minio_secret", "127.0.0.1:9000"); |
| 23 | + |
| 24 | + // Ugly way of avoiding BucketAlreadyOwnedByYou error |
| 25 | + static std::atomic<int> run_id{0}; |
| 26 | + int run = run_id++; |
| 27 | + int i = 0; |
| 28 | + |
| 29 | + for (auto _ : state) { |
| 30 | + state.PauseTiming(); |
| 31 | + auto bucket = std::format("bench-{}-{}-{}", s3b::bucket_name_for(impl.name), run, i++); |
| 32 | + state.ResumeTiming(); |
| 33 | + impl.create_bucket(handle, bucket.c_str()); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +static std::string get_benchmark_name(const std::string &aws_operation, const implementation &impl) { |
| 38 | + const std::string so_name = std::filesystem::path(impl.name).stem(); |
| 39 | + const std::string bench_name = std::format("BENCHMARK_{}_{}", so_name, aws_operation); |
| 40 | + return bench_name; |
| 41 | +} |
| 42 | + |
| 43 | +} // namespace s3b |
| 44 | + |
| 45 | +int main(int argc, char *argv[]) { |
|