Skip to content

Commit

Permalink
Add benchmark for WireKeeper (#122)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #122

This diff adds benchmarks for the WireKeeper. I opted to not include the batch or arithmetic API (for now at least), since they are implemented the exact same way as the boolean, non-batch API.

Reviewed By: chualynn

Differential Revision: D35035761

fbshipit-source-id: d28cbfcc53772a9247015f937353be6673c01b1b
  • Loading branch information
Elliott Lawrence authored and facebook-github-bot committed Mar 23, 2022
1 parent 9b6a89f commit 5e47cbc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions fbpcf/scheduler/test/benchmarks/SchedulerBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
73 changes: 73 additions & 0 deletions fbpcf/scheduler/test/benchmarks/WireKeeperBenchmark.h
Original file line number Diff line number Diff line change
@@ -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 <folly/Benchmark.h>

#include "fbpcf/scheduler/WireKeeper.h"

const bool unsafe = true;

namespace fbpcf::scheduler {

#define BENCHMARK_WIREKEEPER \
folly::BenchmarkSuspender braces; \
auto wireKeeper = WireKeeper::createWithVectorArena<unsafe>(); \
std::vector<IScheduler::WireId<IScheduler::Boolean>> 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<unsafe>();
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

0 comments on commit 5e47cbc

Please sign in to comment.