c++ - 如何在 https://quick-bench.com 上对 fmt::format API 进行基准测试

标签 c++ benchmarking fmt

我正在尝试理解和基准测试 fmt::format API ( https://fmt.dev/latest/api.html )。我在编译器资源管理器中写了一个简单的测试,即 https://godbolt.org/z/fMcf3nczE .

#include <benchmark/benchmark.h>
#include <fmt/core.h>

static void BM_format(benchmark::State& state) {
  // Perform setup here
  for (auto _ : state) 
  {
      std::string s = fmt::format( "{}", "testing fmt::format in benchmark");
  }
}
// Register the function as a benchmark
BENCHMARK(BM_format);
// Run the benchmark
BENCHMARK_MAIN();

然后,我从编译资源管理器启动了 quick-bench。 在 quick-bench 中,它给出了一个错误

Error or timeout bench-file.cpp:2:10: fatal error: fmt/core.h: No such file or directory 2 | #include <fmt/core.h> | ^~~~~~~~~~~~ compilation terminated.

quick-bench 是否支持 c++ fmt 库以便编译和执行?如果没有,还有其他选择。

最佳答案

不幸的是,quick-bench 不支持需要单独编译的外部库 (as fmt does)。作为旁注,它确实 not support the inclusion of header-only libraries via URLs, either .

我会说,在这种特定情况下,如果您没有专门绑定(bind)到 fmt lib,则可以改用 C++20 std::format。但不幸的是,clang 14 和 gcc 11(或者更确切地说,libc++ 和 libstdc++)都还没有实现它。

所以我担心你的要求现在根本不可能。您需要在自己的计算机上进行基准测试。

关于c++ - 如何在 https://quick-bench.com 上对 fmt::format API 进行基准测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72754623/

相关文章:

c++ - 如何在仅 header 模式下使用 fmt 库?

c++ - 使用分配给函数返回值的局部变量或直接使用函数

c++ - 初始化列表使变量未初始化?

java - 通过 .sh 脚本对 java jar 进行基准测试

python - 为什么 CPython 在 "slowspitfire"和 "waf"这两个测试中比 PyPy 快?

c++ - 为什么 fmt::format 不接受字符串作为参数?

c++ - 使用 C++ 更改 QML 单例的属性

c++ - 简单的 cin cout 代码由 "build and run"运行,但在 bin/debug/x.exe 中不起作用

python - Python 代码在函数中运行得更快是真的吗?

c++ - 使用 {fmt} 引用一个字符串