Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 6f0408e

Browse files
author
Ian Sturdy
authored
Add a benchmark for RandomBuffer (#125)
1 parent a73894c commit 6f0408e

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

opencensus/common/internal/random_benchmark.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,37 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <cstdint>
16+
#include <vector>
17+
1518
#include "benchmark/benchmark.h"
1619
#include "opencensus/common/internal/random.h"
1720

1821
namespace {
1922

2023
void BM_GetRandom(benchmark::State& state) {
21-
while (state.KeepRunning()) {
24+
for (auto _ : state) {
2225
::opencensus::common::Random::GetRandom();
2326
}
2427
}
2528
BENCHMARK(BM_GetRandom);
2629

2730
void BM_Random64(benchmark::State& state) {
28-
while (state.KeepRunning()) {
31+
for (auto _ : state) {
2932
::opencensus::common::Random::GetRandom()->GenerateRandom64();
3033
}
3134
}
3235
BENCHMARK(BM_Random64);
3336

37+
void BM_RandomBuffer(benchmark::State& state) {
38+
const size_t size = state.range(0);
39+
std::vector<uint8_t> buffer(size);
40+
for (auto _ : state) {
41+
::opencensus::common::Random::GetRandom()->GenerateRandomBuffer(
42+
buffer.data(), size);
43+
}
44+
}
45+
BENCHMARK(BM_RandomBuffer)->Range(1, 16);
46+
3447
} // namespace
3548
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)