diff --git a/fbpcf/scheduler/test/benchmarks/SchedulerBenchmark.cpp b/fbpcf/scheduler/test/benchmarks/SchedulerBenchmark.cpp index f62883bb..dd2ca977 100644 --- a/fbpcf/scheduler/test/benchmarks/SchedulerBenchmark.cpp +++ b/fbpcf/scheduler/test/benchmarks/SchedulerBenchmark.cpp @@ -10,6 +10,7 @@ #include "common/init/Init.h" #include "fbpcf/scheduler/test/benchmarks/AllocatorBenchmark.h" +#include "fbpcf/scheduler/test/benchmarks/WireKeeperBenchmark.h" int main(int argc, char* argv[]) { facebook::initFacebook(&argc, &argv); diff --git a/fbpcf/scheduler/test/benchmarks/WireKeeperBenchmark.h b/fbpcf/scheduler/test/benchmarks/WireKeeperBenchmark.h new file mode 100644 index 00000000..cd174b58 --- /dev/null +++ b/fbpcf/scheduler/test/benchmarks/WireKeeperBenchmark.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +#include "fbpcf/scheduler/WireKeeper.h" + +const bool unsafe = true; + +namespace fbpcf::scheduler { + +#define BENCHMARK_WIREKEEPER \ + folly::BenchmarkSuspender braces; \ + auto wireKeeper = WireKeeper::createWithVectorArena(); \ + std::vector> wireIds; \ + for (auto i = 0; i < n; i++) { \ + wireIds.push_back(wireKeeper->allocateBooleanValue()); \ + } \ + braces.dismiss(); \ + while (n--) + +BENCHMARK(WireKeeperBenchmark_allocateBooleanValue, n) { + folly::BenchmarkSuspender braces; + auto wireKeeper = WireKeeper::createWithVectorArena(); + braces.dismiss(); + + while (n--) { + wireKeeper->allocateBooleanValue(); + } +} + +BENCHMARK(WireKeeperBenchmark_getBooleanValue, n) { + BENCHMARK_WIREKEEPER { + wireKeeper->getBooleanValue(wireIds.at(n)); + } +} + +BENCHMARK(WireKeeperBenchmark_setBooleanValue, n) { + BENCHMARK_WIREKEEPER { + wireKeeper->setBooleanValue(wireIds.at(n), n & 1); + } +} + +BENCHMARK(WireKeeperBenchmark_getFirstAvailableLevel, n) { + BENCHMARK_WIREKEEPER { + wireKeeper->getFirstAvailableLevel(wireIds.at(n)); + } +} + +BENCHMARK(WireKeeperBenchmark_setFirstAvailableLevel, n) { + BENCHMARK_WIREKEEPER { + wireKeeper->setFirstAvailableLevel(wireIds.at(n), n); + } +} + +BENCHMARK(WireKeeperBenchmark_increaseReferenceCount, n) { + BENCHMARK_WIREKEEPER { + wireKeeper->increaseReferenceCount(wireIds.at(n)); + } +} + +BENCHMARK(WireKeeperBenchmark_decreaseReferenceCount, n) { + BENCHMARK_WIREKEEPER { + wireKeeper->decreaseReferenceCount(wireIds.at(n)); + } +} +} // namespace fbpcf::scheduler