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>
125 lines
2.9 KiB
Python
125 lines
2.9 KiB
Python
# 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
|
|
#
|
|
# Trivial, single-file testing libraries. More complex libraries should get
|
|
# their own directory.
|
|
|
|
load("//bazel/cc_rules:defs.bzl", "cc_library", "cc_test")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
# This does extra initialization on top of googletest's gtest_main in order to
|
|
# provide stack traces on unexpected exits, because we normally rely on LLVM
|
|
# code for that.
|
|
#
|
|
# This replaces "@googletest//:gtest_main";
|
|
# "@googletest//:gtest" should still be used directly.
|
|
cc_library(
|
|
name = "gtest_main",
|
|
testonly = 1,
|
|
srcs = ["gtest_main.cpp"],
|
|
deps = [
|
|
":global_exe_path",
|
|
"//common:init_llvm",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
# This does extra initialization on top of Google benchmark's main in order to
|
|
# provide stack traces and setup LLVM.
|
|
#
|
|
# This replaces `@google_benchmark//:benchmark_main`;
|
|
# `@google_benchmark//:benchmark` should still be used directly.
|
|
cc_library(
|
|
name = "benchmark_main",
|
|
testonly = 1,
|
|
srcs = ["benchmark_main.cpp"],
|
|
deps = [
|
|
":benchmark_helpers",
|
|
":global_exe_path",
|
|
"//common:init_llvm",
|
|
"@abseil-cpp//absl/flags:parse",
|
|
"@google_benchmark//:benchmark",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "benchmark_helpers",
|
|
testonly = 1,
|
|
srcs = ["benchmark_helpers.cpp"],
|
|
hdrs = ["benchmark_helpers.h"],
|
|
deps = ["//common:check"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "capture_std_streams",
|
|
testonly = 1,
|
|
srcs = ["capture_std_streams.cpp"],
|
|
hdrs = ["capture_std_streams.h"],
|
|
deps = [
|
|
"//common:ostream",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "file_helpers",
|
|
testonly = 1,
|
|
srcs = ["file_helpers.cpp"],
|
|
hdrs = ["file_helpers.h"],
|
|
deps = [
|
|
"//common:error",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "global_exe_path",
|
|
testonly = 1,
|
|
srcs = ["global_exe_path.cpp"],
|
|
hdrs = ["global_exe_path.h"],
|
|
deps = [
|
|
"//common:check",
|
|
"//common:exe_path",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "global_exe_path_test",
|
|
size = "small",
|
|
srcs = ["global_exe_path_test.cpp"],
|
|
deps = [
|
|
":global_exe_path",
|
|
":gtest_main",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "unified_diff",
|
|
testonly = 1,
|
|
hdrs = ["unified_diff.h"],
|
|
deps = [
|
|
"//common:check",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "unified_diff_test",
|
|
size = "small",
|
|
srcs = ["unified_diff_test.cpp"],
|
|
deps = [
|
|
":gtest_main",
|
|
":unified_diff",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|