perf-sanity.cc 764 B

12345678910111213141516171819202122232425
  1. // A quick and dirty performance test.
  2. // For actual benchmarks see https://github.com/fmtlib/format-benchmark.
  3. #include <atomic>
  4. #include <chrono>
  5. #include <iterator>
  6. #include "fmt/format.h"
  7. int main() {
  8. const int n = 10000000;
  9. auto start = std::chrono::steady_clock::now();
  10. for (int iteration = 0; iteration < n; ++iteration) {
  11. auto buf = fmt::memory_buffer();
  12. fmt::format_to(std::back_inserter(buf),
  13. "Hello, {}. The answer is {} and {}.", 1, 2345, 6789);
  14. }
  15. std::atomic_signal_fence(std::memory_order_acq_rel); // Clobber memory.
  16. auto end = std::chrono::steady_clock::now();
  17. // Print time in milliseconds.
  18. std::chrono::duration<double> duration = end - start;
  19. fmt::print("{:.1f}\n", duration.count() * 1000);
  20. }