mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-10 12:28:25 +00:00
We use the dry-run mode for running benchmarks in a test. This is important, but doesn't need to use large batches of files. Doing so would cause the compilation benchmark to become excessively slow, especially on GitHub runners. Sadly, Google Benchmark doesn't expose its dry-run mode, but we already have our own `main` function that injects custom logic for our benchmarks. Extend that to detect the dry run flags and environment variables so that we can customize the benchmark behavior in that mode. Then we use that detection to reduce the batch size. Also cleans up the counters computation to both be a bit better organized (I think), and to avoid keeping the tokenized buffers we build to count tokens around during the timed running of the benchmark. Also cleans up a bug in some clamping code spotted while fixing this. Assisted-by: Antigravity with Gemini --------- Co-authored-by: Dana Jansens <danakj@orodu.net>
28 lines
760 B
C++
28 lines
760 B
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "testing/base/benchmark_helpers.h"
|
|
|
|
#include <optional>
|
|
|
|
#include "common/check.h"
|
|
|
|
static constinit std::optional<bool> benchmark_dry_run = {};
|
|
|
|
namespace Carbon::Testing {
|
|
|
|
auto IsBenchmarkDryRun() -> bool {
|
|
CARBON_CHECK(benchmark_dry_run,
|
|
"queried `IsBenchmarkDryRun` before it was set");
|
|
return *benchmark_dry_run;
|
|
}
|
|
|
|
auto SetBenchmarkDryRun(bool is_dry_run) -> void {
|
|
CARBON_CHECK(!benchmark_dry_run,
|
|
"called `SetBenchmarkDryRun` more than once");
|
|
benchmark_dry_run = is_dry_run;
|
|
}
|
|
|
|
} // namespace Carbon::Testing
|