================ @@ -0,0 +1,234 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains basic benchmarks for clang-doc's implementation and +/// library components. +/// +//===----------------------------------------------------------------------===// + +#include "BitcodeReader.h" +#include "BitcodeWriter.h" +#include "ClangDoc.h" +#include "Generators.h" +#include "Representation.h" +#include "Serialize.h" +#include "benchmark/benchmark.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Tooling/Execution.h" +#include "clang/Tooling/Tooling.h" +#include "llvm/Bitstream/BitstreamWriter.h" +#include <string> +#include <vector> + +namespace clang { +namespace doc { + +class BenchmarkVisitor : public RecursiveASTVisitor<BenchmarkVisitor> { +public: + explicit BenchmarkVisitor(const FunctionDecl *&Func) : Func(Func) {} + + bool VisitFunctionDecl(const FunctionDecl *D) { + if (D->getName() == "f") { + Func = D; + return false; + } + return true; + } + +private: + const FunctionDecl *&Func; +}; + +// --- Mapper Benchmarks --- + +static void BM_EmitInfoFunction(benchmark::State &State) { + std::string Code = "void f() {}"; + std::unique_ptr<clang::ASTUnit> AST = clang::tooling::buildASTFromCode(Code); + const FunctionDecl *Func = nullptr; + BenchmarkVisitor Visitor(Func); + Visitor.TraverseDecl(AST->getASTContext().getTranslationUnitDecl()); + assert(Func); + + clang::comments::FullComment *FC = nullptr; + Location Loc; + + for (auto _ : State) { + auto Result = serialize::emitInfo(Func, FC, Loc, /*PublicOnly=*/false); + benchmark::DoNotOptimize(Result); + } +} +BENCHMARK(BM_EmitInfoFunction); + +static void BM_Mapper_Scale(benchmark::State &State) { + std::string Code; + for (int i = 0; i < State.range(0); ++i) { + Code += "void f" + std::to_string(i) + "() {}\n"; + } + + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); + DiagnosticOptions DiagOpts; + DiagnosticsEngine Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()); + + for (auto _ : State) { + tooling::InMemoryToolResults Results; + tooling::ExecutionContext ECtx(&Results); + ClangDocContext CDCtx(&ECtx, "test-project", false, "", "", "", "", "", {}, + Diags, false); ---------------- CarlosAlbertoEnciso wrote:
The `false` value can not be converted to the `OutputFormatTy` type. https://github.com/llvm/llvm-project/pull/182620 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
