Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more compile benchmark stats #4408

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions toolchain/driver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ cc_binary(
"//testing/base:global_exe_path",
"//testing/base:source_gen_lib",
"//toolchain/install:install_paths_test_helpers",
"//toolchain/testing:compile_helper",
"@google_benchmark//:benchmark",
"@llvm-project//llvm:Support",
],
Expand Down
35 changes: 22 additions & 13 deletions toolchain/driver/compile_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "testing/base/source_gen.h"
#include "toolchain/driver/driver.h"
#include "toolchain/install/install_paths_test_helpers.h"
#include "toolchain/testing/compile_helper.h"

namespace Carbon::Testing {
namespace {
Expand Down Expand Up @@ -96,18 +97,30 @@ static auto BM_CompileAPIFileDenseDecls(benchmark::State& state) -> void {
int num_files = ComputeFileCount(target_lines);
llvm::OwningArrayRef<std::string> sources(num_files);

// Create a collection of random source files. Average the actual number of
// lines resulting so we can use that to compute the compilation speed as a
// line-rate counter.
double avg_lines = 0.0;
// Create a collection of random source files. Compute average statistics for
// counters for compilation speed.
CompileHelper compile_helper;
double total_bytes = 0.0;
double total_tokens = 0.0;
double total_lines = 0.0;
for (std::string& source : sources) {
source = bench.gen().GenAPIFileDenseDecls(target_lines,
SourceGen::DenseDeclParams{});
avg_lines += llvm::count(source, '\n');
}
avg_lines /= sources.size();

// Setup the sources as files for compilation.
total_bytes += source.size();
total_tokens += compile_helper.GetTokenizedBuffer(source).size();
total_lines += llvm::count(source, '\n');
};
state.counters["Bytes"] =
benchmark::Counter(total_bytes / sources.size(),
benchmark::Counter::kIsIterationInvariantRate);
state.counters["Tokens"] =
benchmark::Counter(total_tokens / sources.size(),
benchmark::Counter::kIsIterationInvariantRate);
state.counters["Lines"] =
benchmark::Counter(total_lines / sources.size(),
benchmark::Counter::kIsIterationInvariantRate);

// Set up the sources as files for compilation.
llvm::OwningArrayRef<std::string> file_names = bench.SetUpFiles(sources);
CARBON_CHECK(static_cast<int>(file_names.size()) == num_files);

Expand All @@ -132,10 +145,6 @@ static auto BM_CompileAPIFileDenseDecls(benchmark::State& state) -> void {
i += static_cast<ssize_t>(success);
}
}

// Compute the line-rate of these compilations.
state.counters["Lines"] = benchmark::Counter(
avg_lines, benchmark::Counter::kIsIterationInvariantRate);
}

// Benchmark from 256-line test cases through 256k line test cases, and for each
Expand Down
Loading