benchmark_main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include <benchmark/benchmark.h>
  5. #include "absl/flags/parse.h"
  6. #include "common/init_llvm.h"
  7. #include "testing/base/global_exe_path.h"
  8. auto main(int orig_argc, char** orig_argv) -> int {
  9. // Do LLVM's initialization first, this will also transform UTF-16 to UTF-8.
  10. Carbon::InitLLVM init_llvm(orig_argc, orig_argv);
  11. Carbon::Testing::SetExePath(orig_argv[0]);
  12. // Inject a flag to override the defaults for benchmarks. This can still be
  13. // disabled by user arguments.
  14. llvm::SmallVector<char*> injected_argv_storage(orig_argv,
  15. orig_argv + orig_argc + 1);
  16. char injected_flag[] = "--benchmark_counters_tabular";
  17. injected_argv_storage.insert(injected_argv_storage.begin() + 1,
  18. injected_flag);
  19. char** argv = injected_argv_storage.data();
  20. int argc = injected_argv_storage.size() - 1;
  21. benchmark::Initialize(&argc, argv);
  22. absl::ParseCommandLine(argc, argv);
  23. benchmark::RunSpecifiedBenchmarks();
  24. benchmark::Shutdown();
  25. return 0;
  26. }